I have the following program to multiple two numbers:
.globl main
main:
# Store the two numbers temporarily in ebx, ecx
mov $7, %ebx
mov $14, %ecx
# clear out eax and add ebx (7) to it ecx (14) times
mov $0, %eax
multiply_step:
add %ebx, %eax
dec %ecx
jnz multiply_step
ret
However, if I add in variables for the 14
and 7
for whatever reason, the program takes about a second to run, which seems a bit strange (the above program is instantaneous) --
.globl main
.globl x,y
x: .byte 7
y: .byte 14
main:
mov x, %ebx
mov y, %ecx
mov $0, %eax
multiply_step:
add %ebx, %eax
dec %ecx
jnz multiply_step
ret
Why does this program take longer to run? I am invoking both as:
$ gcc m2.s -o m2 && ./m2; echo $?
# 98