我需要帮助在Assembly x86中创建这个宏

时间:2012-03-09 01:10:30

标签: assembly x86

我需要创建一个宏“ADD128 N,M”,它将在内存中添加两个无符号数,每个128位,并将总和加到内存中N(N = N + M)

我一直试图让它工作几个小时,我根本无法让它工作。无论我尝试什么,答案都只是0。

以下是我需要添加此宏的代码。

 PAGE    80,132 
;===================================================================
;                   PROGRAM LISTING 5.1
;
; 
;
;===================================================================
        .MODEL  SMALL,BASIC,FARSTACK 
        .386
;===================================================================
                                   ;PROCEDURES TO
       EXTRN   NEWLINE:FAR         ;DISPLAY NEWLINE CHARACTER
       EXTRN   PUTDEC:FAR          ;DISPLAY DECIMAL INTEGER
;===================================================================
; S T A C K   D E F I N I T I O N
;
       .STACK  386







SHL64 MACRO REG1, REG2
    SHL     REG2, 1
    RCL     REG1, 1
    ENDM

SHR64   MACRO   REG1, REG2
    SHR     REG1, 1
    RCR     REG2, 1
    ENDM


;===================================================================
; C O D E   S E G M E N T   D E F I N I T I O N
;
       .CODE
;
EX_5_1:
       MOV     BL,1                ;SET CODE FOR WORD DISPLAY
       MOV     EDI,0001H            ;LOAD AX WITH 0000000000000001
       MOV     ESI,0010H
       MOV     EBX,0001H    
       MOV     EDX,0001H    
       MOV     ECX,0001H
       MOV     DL,1 




       MOV      EAX, EDI
       CALL     PUT_BIN         ;DISPLAY CONTENTS OF AX
       MOV      EAX, ESI
       CALL     PUT_BIN         ;DISPLAY CONTENTS OF AX
       CALL     NEWLINE         ;SKIP TO NEXT LINE ON DISPLAY
       CALL     NEWLINE
       CALL     NEWLINE




       SHL64  EDI,ESI

       MOV      EAX,EDI
       CALL     PUT_BIN
       MOV      EAX,ESI
       CALL     PUT_BIN
       CALL     NEWLINE
       CALL     NEWLINE
       CALL     NEWLINE

        SHR64   EDI,ESI

       MOV      EAX,EDI
       CALL     PUT_BIN
       MOV      EAX,ESI
       CALL     PUT_BIN
       CALL     NEWLINE
       CALL     NEWLINE
       CALL     NEWLINE


        MOV     EAX, EBX
       CALL     PUT_BIN
       MOV      EAX,EDX
       CALL     PUT_BIN
       MOV      EAX, EDI
       CALL     PUT_BIN         ;DISPLAY CONTENTS OF AX
       MOV      EAX, ESI
       CALL     PUT_BIN         ;DISPLAY CONTENTS OF AX
       CALL     NEWLINE         ;SKIP TO NEXT LINE ON DISPLAY
       CALL     NEWLINE
       CALL     NEWLINE

这是我需要做的最后一部分,也是我唯一无法工作的部分。无论谁愿意帮助我都会成为一个救生员!

1 个答案:

答案 0 :(得分:1)

用于添加两个128位存储器地址位置的正确宏是:

ADD128   MACRO n, m
         mov   eax, dword ptr[m]
         add   dword ptr[n], eax
         mov   eax, dword ptr[m + 4]
         adc   dword ptr[n + 4], eax
         mov   eax, dword ptr[m + 8]
         adc   dword ptr[n + 8], eax
         mov   eax, dword ptr[m + 12]
         adc   dword ptr[n + 12], eax
         ENDM