【问题标题】:PUSH and POP out of DWORD in Assembly x86在汇编 x86 中从 DWORD 中推送和弹出
【发布时间】:2013-10-27 02:04:45
【问题描述】:

到目前为止,我尝试了几种方法来打印 DWORD 中的值,但我只能得到第一个或最后一个数字,并且我需要以相反的顺序打印所有 5 个数字。

INCLUDE Irvine32.inc

.data

arr1 DWORD 2, 4, 6, 8, 10

.code
main PROC
    mov ecx,4
    mov esi,0
L1:
    mov eax,arr1[esi]

    push eax 
    sub esi,4
    loop L1
    mov ecx,4   
    mov esi,0
L2:     pop eax
    mov arr1[esi],eax
    add esi,4
    loop L2
    mov esi,OFFSET arr1
    mov ecx,4
L3:
    mov eax,[esi+ecx*4]

    call WriteDec
    sub ecx,4
    call EndLine
    loop L3
    call Crlf

    exit
main ENDP
END main

【问题讨论】:

    标签: loops assembly x86 masm irvine32


    【解决方案1】:

    好的,StackLIFO,这意味着你压入堆栈的最后一个值是第一个弹出的值,对吧?

    如果你这样做:

    push    2
    push    4
    push    6
    push    8
    push    10
    

    然后从堆栈中弹出的第一个值是 10,然后是 8,然后是 6,等等。所以 10 将首先打印。

    我们可以摆脱您的大量代码,因为您只想使用 pop 以相反的顺序打印值。

    main PROC
        mov     ecx, 5
        mov     esi, 0
    L1:
        push    arr1[esi]   
        add     esi, 4      ; add 4 to arr1 pointer
        loop    L1          ; loop until ecx == 0
    
        mov     ecx, 5      ; reset loop counter
    L3:
        pop     eax
        call    WriteDec
        call    Crlf
        loop    L3
    
        call    Crlf
        call    WaitMsg
        exit
    main ENDP
    

    【讨论】:

    • 谢谢你,现在这很有意义,我正在做额外的步骤。非常感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2017-09-27
    • 2015-01-09
    • 2014-08-04
    • 2015-06-20
    • 2022-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多