Reputation: 243
I am not getting the expected output. I have a loop that should continue 10x, then the second loop that should continue 10x times. Loops should print seperately
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
I am getting
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
but im expecting first first first first first first first first first first second second second second second second second second second second
I am new to assembly (NASM), what am i doing wrong?
Upvotes: 0
Views: 79
Reputation: 134125
The problem is in your definition here:
section .data
msg1: db "first",10,0
msg2: db "second",10,0
len1: equ $-msg1
len2: equ $-msg2
Here you're saying that msg1
includes all of the first message and the second message.
That should be
msg1: db "first",10,0
len1: equ $-msg1
msg2: db "second",10,0
len2: equ $-msg2
Upvotes: 3