Hi folks, I'm trying to do something which I figure would be rather easy, though I'm beign proven terribly wrong. I'm probably doign something really dumb. Before I explain, here's my code:
.data
mynum:
.int 75
format:
.string "Value: %d\n"
.text
.globl main
main:
movl $0, %eax
# Add the number
addl $mynum, %eax
# Print it out
pushl %eax
pushl $format
call printf
addl $8, %esp
movl $1,%eax
xorl %ebx,%ebx
int $0x80
ret
Pretty straightforward:
- Add a number onto the accumulator (that has been declared in the
.data
section) - Print the number out
Now the problem that I'm having is this: when the code runs, instead of printing Value: 75
like I'd hope, it's giving me Value: 134518172
.
My assumption is that a bunch of bits are being passed that should be being passed. Where they're coming from, I'm not sure. In fact, I don't even know what they are.
One thing I've tried is using movb
to clear out the first and last halves of the accumulator, but it hasn't made any significant difference (it has changed the number, but only by ~1000 in either direction):
movb $0, %ah
and
movb $0, %al
Thanks in advance