Assembly Language/accessing arguments as arrays
Expert: Moskovitz Eliezer - 10/7/2000
QuestionI know basically how to access an array if its created in .rodata or .data sections but when passed on the stack I`m not so sure. Maybe I should tell you exactly what I`m trying to do...I need to create an "add" function that accepts arguments x,y,z. x and y are 128bit integers that must be added and the answer must be stored in z. So I figure I have to access x and y 32 bits at a time, like an array...add them, somehow store the answer to the correct offset in z, check for carry, add that on to the next 32 bits, add the next 32 bits, etc. Does that algorithm sound right? Assuming it is I`ve tried to do this as follows (very wrong, incomplete, I know...I`ve only been programming in assembler for a few weeks):
.equ INT,4
.global main
main:
movl $0,%esi
While:
cmpl $12,%esi
je EndWhile
movl ($x,%esi),%eax
movl ($y,%esi),%ebx
addl %ebx,%eax
movl %eax,z
While2:
pushf
popl %eax
movl $b11000000000000000000000000000000,%ebx
and %ebx,%eax
cmpl $b11000000000000000000000000000000,%eax
je EndWhile2
addl $8,%esi
addl $1,($x,%esi)
EndWhile2:
jmp While
EndWhile: /*set flags*/
Display: ...
Any help at all would be appreciated.
AnswerI'm sending it again with more info at the end :
first I want to say that I'm doing mostly code with 16bit instractions so I can't help you a lot. I did notic that I can't see a normal code here so my guess is:
1. you are not using masm to compile
2. you still don't know how to write a good for the compiler
and now for the question:
first I think that the 128bit data is in intel style format: that is from low byte to high byte
in example : 0102h will be the number 2*256+1=513
I know that the intel commands works that way
now the best way to make a loop is to use cx and the loop command:
mov cx,4
loopstart :
; you code here
; notice that I use ; for lines that the compiler will
; ignore
loop loopstart ; end of loop
now to do what you want we shell use 2 commands (instractions) 1.add 2.adc
add can get eax,ebx, etc etc and so can adc
the diffrent is that add simply add and adc add the carry also so you don't need to check the carry and add one this code should do it for you.
and now I didn't see why you needed the stack, your best way is to stay with the data segment. and last : use mov [ebx],eax (I hope) to move data from memory address ebx to eax.
mail me for more help.
Mosko
added:
try
http://www.strangecreations.com/library/assembly/tutor/asm5.htm