如何在不使用循环的情况下以汇编语言添加数字?

时间:2019-02-27 16:58:21

标签: math assembly x86 irvine32

我需要这个程序才能打印出1 + 3 + 4 + 10 = 18,但是到目前为止我还没有成功。我可以单独打印18个,但这不是我要做的。我不允许使用循环。有人可以帮我吗?

INCLUDE Irvine32.inc
.data

y1 DWORD 1
y2 DWORD 3
y3 DWORD 4
y4 DWORD 10

plus byte " + ",0
equal byte " = ",0

.code

main PROC




exit

main ENDP
END main

1 个答案:

答案 0 :(得分:0)

好,我昨晚花了整个时间才弄清楚,但这行得通。

INCLUDE Irvine32.inc  ; like import
.data

y1 dword 1
y2 dword 3
y3 dword 4
y4 dword 10

plus byte " + ",0
equal byte " = ",0;

.code

main PROC
    mov eax,0
    mov edx,offset plus
    mov ebx,0
    mov eax,y1
    call writedec
    add ebx,eax
    call writestring
    mov eax,y2
    call writedec
    add ebx,eax
    call writestring
     mov eax,y3
    call writedec
    add ebx,eax
    call writestring 
     mov eax,y4
    call writedec
    add ebx,eax
    mov edx,offset equal
    call writestring
    mov eax,ebx
    call writedec

   exit

main ENDP

end main