Inferno #04
22 июня 2003

For Coderz - Macros for assembler Alasm v4.4x.

<b>For Coderz</b> - Macros for assembler Alasm v4.4x.
    On a macro poor Say a Word ...

(C) Vitamin / CAIG:


   Probably many coders (at least starting to) complained of 
some shortcomings assembly, which, however, were absent in a 
higher level language. This is a question I'm about 
constructions. But because if you can not make the assembler

in Pascal, or anything else, do something
programming more convenient. To implement such a venture, we 
need assembler supports macros. The examples below are written 
by Alasm v4.4x. At a special wish they can be converted into 
any other Macroassembler. So Now, start with one that is two 
simple macros that can do the job with

variables more convenient than before.


     MACRO GET

     IFN?: 1 +1; check for the presence of

     LD: 0 (: 1) variable

     ELSE

     DISPLAY "Variable: one is not found"

     ENDIF

     ENDM

And a second macro:


     MACRO PUT

     IFN?: 0 +1

     LD (: 0): 1

     ELSE

     DISPLAY "Variable: 0 is not found"

     ENDIF

     ENDM

And use them should be as follows:

xpos equ 32768; declare a variable

     ...

     get b, xpos; thought

     ...

     put xpos, a; recorded


   Registers can be paired.
The variables can not use absolute addresses.


   Just a few macros on this topic.
Suppose we have some complex data structure and we need to ask 
yourself comfortable to its elements. Let the address of the 
structure is stored in the IX. 


     MACRO MOV

     IFN?: 1 +1

     LD: 0, (IX +: 1)

     ELSE

     DISPLAY "Field: one is not defined"

     ENDIF

     ENDM


   Example of use:

BOX DB 0; x

     DB 1; y

     DB 2; width

     DB 3; heigth

BOX_X EQU 0
BOX_Y EQU 1
BOX_W EQU 2
BOX_H EQU 3


     LD IX, BOX

     ...

     MOV A, BOX_X

     ...


   And to finish the topic of variables,
talk about access to bit fields.


     MACRO MASK

     IFN (?: )'(?: 0 +1 1 +1)

     BIT: 0, (IX +: 1)

     ELSE
DISPLAY "Field: 0 or field: one not defined"

     ENDIF

     ENDM


   For example, augment the previous example
lines:

BOX ...

     DB 0; flag


     ...

BOX_FLAG EQU 4

BOX_FULL EQU 0
BOX_TURN EQU 1
BOX_CLOS EQU 2


     ...


     MASK BOX_FULL, BOX_FLAG; check

     JZ ... And if that move


   Similarly, you can add macros to
Installation and removal of bit variables.


   Go ahead. Everyone knows the error output of the field in 
the compilation command relative to the transition. Then we 
take and fix everything at jr jp. And then, when everything is 
soptimizirovano, configured and have the opportunity to replace 
some jp back to jr, but go find them among the heaps of their 
own kind - zae ..., sorry, butt:) And following macro tries to 
do an optimal code, automatically placing jr, where possible, 
but in other cases - jp. 

  But there is one bad feature: it
works well only with specific addresses given, or with already 
defined marks, IMHO feature alasma with his single pass. If 
anything, the compiler generates an error and you change to jmp 
jp. Risk a bit, but in many cases it really will save you 
pyamyat. 


     MACRO JMP

     LOCAL; local labels

     DIFF =: 0 - $ -2; path difference


     IF DIFF '# 8000; if the transition forward


     IF DIFF '# FF80; if you fit in

     DB # 18, DIFF; short transition

     ELSE

     JP: 0, if no

     ENDIF


     ELSE


     DIFF =- DIFF; if the transition back

     IF DIFF '# FF80

     DB # 18,-DIFF

     ELSE

     JP: 0

     ENDIF


     ENDIF

     ENDL

     ENDM


   You can upgrade the macro and
create several new named jz, jnz,
jc, jnc, which will optimize conditional jumps, and the macro 
loop, which will choose between djnz and dec b: jp nz.



   But this macro allows you to copy memory area.


     MACRO COPY

     LOCAL

     OLDADR = $

     DEST =: 0

     ORG: 1

     DUP: 2

     DB {DEST}

     DEST = DEST +1

     EDUP

     ORG $

     ENDL

     ENDM


   And they should use this:
COPY from, to, length. If the length of the block or forward 
multiple of 2, we can fix DB on the DW and DEST = DEST +2. Just 
keep in mind that This macro is very slow -

even slower than BASIC, and adds lines to compile 2 * length. 
He needed to copy the data to be performed external to this 
procedure. 


   Nice collection of macros supplied with alasmom, this counter
builds, and a generator of random garbage:)


   Somehow I gave Steve my drives on
Spectrum, and some gave him a
dude named Unwinder, who was in our group before I came into 
it. So, on one disc, I found a toy, "Python", written entirely 
on the macro and Macro Assembler. It runs at compile time, and 
was adapted for Tasm. Attempts to move it to Alasm failed, 
besides, I do not razobralya in principle of its work. But try 
to find it and provide for public Review.



   To enable this to take leave. If that
come up with - tell a must!

----------------------------------------- Alone Coder:


  For its part, can not comment on that python under ALASM 
writing is more difficult because the resident would have to 
patch ALASM'a that he had included an interrupt when

assembly. Fortunately, he does not seem to
uses non-standard stack ...

... And J7n/4D, programming under TASM, invented
completely insane macro. Interestingly, the
on ALASM it works too!
; MACROS LIBRARY Revision 2.0
; J7n'n'MiKE / 4D 98-2001

     MACRO COP

     IFN: 1
: 0

     COP: 0, :1-1

     ENDIF

     ENDM

   Any team is copied multiple times! And this is in one line!


   But from there, a new variation on the theme
code alignment along the boundary of 256 bytes:

     MACRO OFFSET

     IFN. $

     DS # 100 $ -.

     ENDIF

     ENDM


   Here is my macro poll ports for keyboard. Instead of polling 
the port # FEFE just write "I 2", can be a parameter, then you 
can select the desired key: 

     MACRO i

     LD A, -: 0

     IN A, (-2)
IFN? I :1-2

     AND: 1
ENDIF

     ENDM


   As you can see, my one-letter macros. This is to save space 
in the source. For even more savings Challenges Macros should 
be written on the label field, then is this:

i 2,1

   I wanted to make a macro, but it did not work - Russian 
letters do not mean: 

    ; MACRO s

    ; EX DE, HL

    ; ENDM

   So we have to write the old-fashioned:

     DB "s


   And here's my version of the JP / JR:
; Jp / r (UNDEFINED = JR)

     MACRO j
IFN?: 0

     JR: 0
ELSE
IF: 0 - $ 126 / 256

     JR: 0
ELSE

     JP: 0
ENDIF
ENDIF

     ENDM

   True, I do not use it.


   Check HL-zero with a possible transition to zero. This macro 
is not only diminishes the source, but also allows you to 
change the condition finding the beginning of the text in 
ACEdit. (Macro used in all proveryalku start

text editor.)

     MACRO b

     LD A, H

     OR L
IFN? B :0-2

     JR Z,: 0
ENDIF

     ENDM


   What does the following macro, I hope
obyaslyat should not?

     MACRO [

     LD HL, (: 0)

     CALL: 1

     LD (: 0), HL

     ENDM


   The macro I used for storage
table scan codes keyboard in the format
described in AlCoNews # 6:

     MACRO d

     DB: 0

     DW: 1

     ENDM

   By the way, you can loop! Just yet
question whether it would be advantageous to fit:)


   It's just a copy from somewhere kudato (saves some space in 
the source): 

     MACRO l

     LD HL, (: 0)

     LD (: 1), HL

     ENDM


   Sravnivalka 16-bit chisel.Esli given parameters, and even 
jump on the condition! 

     MACRO s

     OR A

     SBC HL, BC

     ADD HL, BC
IFN? S :0-2

     JR: 0: 1
ENDIF

     ENDM


   That's interesting here is makros.Takie macros, completely 
unexpected, there the optimization program. This sequence of 
commands I have found very popular when looking printout ACE. 
Output these macros - the first step toward finding places

to reduce program length.

   So: a cycle in which something called
and something (register-to-other) increments!

     MACRO c
LOCAL
cc

     CALL: 0
IFN? C :1-2

     INC: 1
ENDIF
IFN? C :2-2

     INC: 2
ENDIF

     DJNZ cc
ENDL

     ENDM


   In fact, one could not verify that the parameters (after 
all, darling, and an undocumented feature ALASM), but then when 
assembling on the screen will be displayed error, that's ugly. 
Besides, better precision confidence as a result! 






Other articles:

Events - On completion of the first part of a virtual musical party The Compo.

Softinka - On operating systems for Spectrum ChAOS and ZXVGS.

Inferno - The authors of the magazine.

Pentagon - Instructions on how to activate unused (zero), the banks ROM in your computer Pentagon.

Pentagon - Instructions for remaking the Pentagon-128 to exit at Reset'u in the 0-th bank ROM 27512.

Gameland - Black Raven Passage of game: Unknown shipment. Disk 1.

Gameland - Black Raven Passage of game: Unknown shipment. Disk 2.

Softinka - Description of the GUI for disk-TR-DOS - ChAOS.

Inferno - On the shell.

Softinka - Editor of two screen graphics DouBleScreen Editor v0.4.

Softinka - Operating system ZXVGS. Composition versions software.

Inferno - Introduction by the editors.

Iron - The results of the development of coders RGB - PAL / NTSC, at the end of 2002.

Gameland - On the game King's Bounty 3, Black Raven: Unknown shipment.

Others - On the survey.

For Coderz - Macros for assembler Alasm v4.4x.

Mathematics - Mandelbrot fractal.

Softinka - Music Editor Pro Tracker v3.71. Features of the program.

Softinka - Format RAR 2.x. Technical information.

Others - Registered users ZXVGS and CPM22QED.

Softinka - File Types defined in the OS ZXVGS.

Softinka - The functions of the operating system ZXVGS.

Softinka - The appearance of the operating system ZXVGS.

Softinka - IDEDOS - access to hard disks in OS ZXVGS.

Softinka - The description of the operating system ZXVGS.

Softinka - MEMDISK - file system for storing files in memory.

Softinka - OS Releases ZXVGS and their differences.

Softinka - Resident System Extensions (RSX) in ZXVGS.

Softinka - Version of the new operating system for Spectrum ZXVGS.

Iron - Advanced Keyboard sinclair-compatible personal computers.

For Coderz - An algorithm for finding the integer part of square root.

Events - Nominees virtual musical party The Compo.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Entry - poems and maintenance facilities.
Topic - the continuation of the opus of Nemo.
Muzoboz - an overview of 8 music demonstrations: Fable Dream Demo, Black Galaxy, Opium Demo, Miles Mix, Chess Board, Mr.Key Gift, Rave Time Xtasy, etc.
Technology sprites - Part 2: The hunt for sprites (search and pulling).

В этот день...   23 November