Click to See Complete Forum and Search --> : code help
horent135
October 10th, 2006, 01:48 AM
i don't really know if im doin this right or not, cuz it my first time. so please help me understand. this is the code i have written. im just trying to inverse data x to y
include irvine32.inc
.data
X SDWORD -3000, -2000, -1000, 0, 1000, 2000, 3000
Y SDWORD 7 DUP (?)
Z SDWORD ?
;in all the below lines use eax instead of ebx
push [ebx]
push [ebx+8]
push [ebx+16]
push [ebx+20]
push [ebx+24]
push [ebx+28]
push [ebx+32]
pop [ebx+32]
pop [ebx+28]
pop [ebx+24]
pop [ebx+20]
pop [ebx+16]
pop [ebx+8]
pop [ebx]
Do not hardcode like this. Instead loop through available number of elements (here signed dword) to be reverse copied.
p.s : Use code tags while posting code
horent135
October 10th, 2006, 02:04 AM
im just trying to put in y 3000,2000,1000,0,-1000,-2000,-3000
the inverse of x.
code
begin:
lea eax,x
lea ebx,y
;swapping x <--> y
next:
mov ax, [eax]
mov bx, [ebx]
mov [ebx], ax
mov [eax], bx
;push y into a stack
push [ebx]
push [ebx+8]
push [ebx+16]
push [ebx+20]
push [ebx+24]
push [ebx+28]
push [ebx+32]
;pop y with the reverse order.
pop [ebx+32]
pop [ebx+28]
pop [ebx+24]
pop [ebx+20]
pop [ebx+16]
pop [ebx+8]
pop [ebx]
so hopefully it ends up 3000,2000,1000,0,-1000,-2000,-3000
kumaresh_ana
October 10th, 2006, 02:12 AM
I am reiterating what I told you earlier.
mov ax, [eax]
mov bx, [ebx]
mov [ebx], ax
mov [eax], bx
Remove these lines. They serve you no purpose.
Push x and pop it in y. You are pushing y and popping y which do not get you where you are going. See my previous post.
p.s : kindly use code tags to post your code
horent135
October 10th, 2006, 02:14 AM
sorry im new, wat do you by code tags?
kumaresh_ana
October 10th, 2006, 02:19 AM
sorry im new, wat do you by code tags?Read it here (http://www.codeguru.com/forum/misc.php?do=bbcode#code)
BTW do you get the point that I am telling you?
horent135
October 10th, 2006, 02:27 AM
include irvine32.inc
.data
X SDWORD -3000, -2000, -1000, 0, 1000, 2000, 3000
Y SDWORD 7 DUP (?)
Z SDWORD ?
pop [ebx+32]
pop [ebx+28]
pop [ebx+24]
pop [ebx+20]
pop [ebx+16]
pop [ebx+8]
pop [ebx]
so this basically works?? i understand that it push x and pop into y. and doing the inverse of x?
kumaresh_ana
October 10th, 2006, 02:37 AM
It should, if you have done everything your assembler demands.
horent135
October 10th, 2006, 02:41 AM
alrite big thanks to you!!
sorry about diffculty :)
kumaresh_ana
October 10th, 2006, 02:52 AM
Anytime! ;)
edit
Sorry, I did not notice one more thing. You need to reverse the pop statements. Also the offests has to be in increments of 4 for both the push and pop statements.
horent135
October 10th, 2006, 03:21 AM
so it should be like this?
include irvine32.inc
.data
X SDWORD -3000, -2000, -1000, 0, 1000, 2000, 3000
Y SDWORD 7 DUP (?)
Z SDWORD ?
;pop the stack and store to y
pop [ebx]
add ebx,4
loop next
mov ecx,7
;sum all
next1:
add ebx,4
loop next1
;stores into z
mov edx,ebx
end
kumaresh_ana
October 11th, 2006, 02:06 AM
Linker happens because you are not including the required library which contains mainCRTStartup function. It seems you are using MASM to build. I have no xp in it. I use only nasm. Refer the documentation of your assembler and linker to work around this problem.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.