Possible duplicate exist, but I couldnt figure out how to apply this or othere solutions to similar problems so here I am.
I am creating a function that returns and integer as a string in x86 AT&T Assembly.
I have this code to declare the variable resdes
.
.data
.align 4
resdes: .long 12
resdes
now points to a memory location followed by 11 other bytes free for me to use (I have understood this correctly?).
I want to load one digit at a time from the integer into the bytes one by one. this is my code:
ifd:
movl (%esp, %ecx), %eax //This loads %eax with my int
movl resdes, %ecx //This is incorrect and causes errors later
inc %ecx
movl $10, %ebx //Division by 10 to basically do a modulo operation
cdq
divloop:
div %ebx
movb %dl, (%ecx) //This is where I move the digit into the memory
//And here I get the ERROR because (%ecx) does
//not contain the proper address
inc %ecx //And set the pointer to point to the next byte
cmp $0, %eax //If there are noe more digits left we are finished
je divfinish1
jmp divloop //I leave out alot of the code that I know
//work because it's not relevant
My problem is getting this actual address of resdes
into the %ecx
register, the first line in the above code. As far as I know the line moves the contents of the resdes
-address into %ecx
, and this is not what I want.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…