Reputation: 63
This is a function in assembly to take input from the user in 2 strings "size" and "per",
but it only takes 1 input and then starts crashing.
I need help. Thank you in advance.
input:
mov si,0
lb :
mov ah,0
int 16h
cmp al,0x0d
je 2nd
mov [size + si],al
inc si
loop lb
2nd:
mov si,0
lb1:
mov ah,0
int 16h
mov [per + si],al
cmp al,0x0d
je 3rd
inc si
loop lb1
3rd:
ret
Upvotes: 1
Views: 1057
Reputation: 39166
To create a loop it's not mandatory to use the loop
instruction!
In your 1st loop, after storing the character in size and after incrementing the pointer in SI
, you need to always jump back to the top of your loop. The correct instruction then is jmp lb
, an unconditional jump to the label lb.
input:
mov si, 0
lb :
mov ah, 0
int 16h
cmp al, 0x0d
je 2nd
mov [size + si], al
inc si
jmp lb ; The unconditional jump
2nd:
In your 2nd loop, after incrementing the pointer in SI
, you need to always jump back to the top of this loop. The correct instruction then is jmp lb1
, an unconditional jump to the label lb1.
mov si, 0
lb1:
mov ah, 0
int 16h
mov [per + si], al
cmp al, 0x0d
je 3rd
inc si
jmp lb1 ; The unconditional jump
3rd:
ret
One thing that you should be aware of is where you check for the ENTER key (ASCII 13):
This difference is probably not what you expect.
Upvotes: 1