Reputation: 13
I am currently trying to teach myself x86 under the circumstances posted in my title. Please note I do not just want an answer, I want to learn this and be fluent in it.
I am having a lot of trouble storing data in memory addresses other than the main registers (eax
, ebx
, ecx
, edx
).
.global main
.text
str: .string "data: %d\n"
main:
pushl $3
call malloc
popl %ecx
movl $4, %esi #source
movl %eax, %edi #destination
stosb
movl %eax, %esi
lodsb
pushl %edi
pushl $str
call printf
popl %ecx
popl %ecx
After the stosb
, shouldn't movl
put the destination address (memory address produced from malloc
, and original source address) into the destination address, and move the $4
in %esi
back into %edi
?
Upvotes: 0
Views: 1334
Reputation: 9377
It's not quite clear what you are trying to do. However, note that stosb
does not make any use of esi
(or ecx
). rep stosb
will make use of ecx
: read the descriptions of both forms of that instruction carefully and make sure you are doing the right thing.
You can download Intel's reference manual from this page.
Upvotes: 0
Reputation: 223193
stosb
stores a single byte. In x86, an address is a dword, so you needed to use stosd
instead. (Remember that stosb
and lodsb
write to/read from %al
, and stosd
and lodsd
write to/read from %eax
.)
Also, your $4
was initially stored in %esi
, but that was later overwritten by the movl %eax, %esi
instruction.
Upvotes: 1