0

我没有得到预期的输出。我有一个应该继续 10 倍的循环,然后是应该继续 10 倍的第二个循环。循环应该单独打印

section .data
    msg1:   db  "first",10,0
    msg2:   db  "second",10,0
    len1:   equ $-msg1
    len2:   equ $-msg2
section .bss
    num resb    1    ;reserve 1 byte
section .text
    global main
main:
    mov [num], BYTE 10d ;num = 10
    loop:
    mov edx,    len1
    mov ecx,    msg1
    mov ebx,    1
    mov eax,    4
    int 80h
    dec BYTE [num]      ; num--
    cmp [num], BYTE 0
    jnz loop        ; jump if not equal to zero

    mov [num], BYTE 20d ; num = 20
    loop2:
    mov edx,    len2
    mov ecx,    msg2
    mov ebx,    1
    mov eax,    4
    int 80h
    sub [num], BYTE 2   ; num = num - 2
    cmp [num], BYTE 0
    ja loop2        ; jump if above 0

    mov eax,    1
    mov ebx,    0
    int 80h

我正进入(状态 first second first second first second first second first second first second first second first second first second first second second second second second second second second second second second

但我期待first first first first first first first first first first second second second second second second second second second second

我是装配新手(NASM),我做错了什么?

4

1 回答 1

3

问题出在您的定义中:

section .data
msg1:   db  "first",10,0
msg2:   db  "second",10,0
len1:   equ $-msg1
len2:   equ $-msg2

在这里,您说的是msg1包括所有第一条消息和第二条消息。

那应该是

msg1:   db  "first",10,0
len1:   equ $-msg1

msg2:   db  "second",10,0
len2:   equ $-msg2
于 2013-08-13T21:26:28.073 回答