简体   繁体   中英

MASM assembly language(x86) macros (CBW,LOOP, PTR)

Suppose your assembler does not have the operations CBW, LOOP and PTR, how can you design a macro for each of theses?

Example:

    MCBW macro
    move AX,0
    div AX,CH
    endm

Loop macro:

;//---------------------------------------------------------------------------
myLoop MACRO myLabel:REQ
;//---------------------------------------------------------------------------

    dec ecx
    jnz myLabel

ENDM

in proc example:

mov ecx, 5
mov eax, 0
ANY_LOOP:
   inc eax
myLoop ANY_LOOP

CBW macro:

;//---------------------------------------------------------------------------
myCBW MACRO
;//---------------------------------------------------------------------------
    mov ebx, eax
    and eax, 080h
    shl ax, 1
    xchg ah, al
    mov ecx, 0FFFFh
    mul ecx
    mov al, bl

ENDM

in proc example:

mov eax, 8Fh
myCBW

PTR macro:

;//---------------------------------------------------------------------------
myPointer MACRO source:REQ
;//---------------------------------------------------------------------------
    exitm <[source]>

ENDM

in proc example:

.data
    number  DWORD 5

.code
    main PROC

    mov eax, myPointer(number) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM