Reputation: 49
I have recently been following a tutorial on x86 programming. Here is a program written in x86 NASM, that is supposed to display all 256 (displayable) ASCII characters.
However, I observe a possibly redundant line of code, the mov instruction in line 17, and the cmp instruction in line 18. As you can see, there are no other instructions in the code that use the zero flag that it activates, such as control loops.
I tested the code with and without that cmp instruction and mov instruction, here is with it:
└─$ ./example_displayascii
0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������
Here is without (either of those 2 instructions):
└─$ ./example_displayascii
0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������
Does exactly the same thing. I suspect that this is a debug line left there for no reason. Please take a look and see if it has any intent. Thanks!
Here is the text code if you need it:
section .data
achar db '0'
section .text
global main:
main:
call display
mov eax, 1
int 0x80
display:
mov ecx, 256
next:
push ecx
mov eax, 4
mov ebx, 1
mov ecx, achar
mov edx, 1
int 80h
pop ecx
;mov dx, [achar]
;cmp byte[achar], 0dh
inc byte[achar]
loop next
ret
Upvotes: 2
Views: 64