Question: The code below works, but I wanted to know why it works, since to my knowledge, this code: mov [ array + eax ] ,
The code below works, but I wanted to know why it works, since to my knowledge, this code:
mov array eax ebx
mov ecx, array eax
found under loopstart, should need to be:
mov array eax ebx
mov ecx, array eax
And in other code I have written, I have had to do that, with the lack of a making the code not work. In this case, however, the opposite is true, and I have to remove the for the code to give the intended output. If I leave the the loop stops counting at even though it is meant to count to This is odd because the code above doesn't even touch the counter variable. The full code is below, please advise.
extern printf ; the C function, to be called
global main ; the standard gcc entry point
section bss ; BSS uninitialized identifiers
array resw
count resd
value resd
section data ; Data section, initialized identifiers
fmt db "Array index: d Value: d
section rodata ; Readonly section, immutable identifiers
section text ; Code section.
main: ; the program label for the entry point
; Don't change or remove the lines of code in here
push ebp ; set up stack frame
mov ebp, esp ;
; Don't change or remove the lines of code in here
;
; Your NASM code will go in here
;
; Move number into counter and value
mov dword count
mov dword value
loopstart:
; Compare count to greater than or equal then end loop
cmp dword count
jge loopend
; Move into array
mov eax, count
mov ebx, value
mov array eax ebx
mov ecx, array eax
; Print output
push dword ecx
push dword count
push fmt
call printf
add esp,
; Increment the counter
add dword count
add dword value
; Restart loop
jmp loopstart
loopend:
; Don't change or remove the lines of code in here
mov esp, ebp ; takedown stack frame
pop ebp ;
;
mov eax, ; no error return value
ret ; return
; Don't change or remove the lines of code in here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
