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 ?

.code
begin:
lea eax,x
lea ebx,y

next:
mov ax, [eax]
mov bx, [ebx]
mov [ebx], ax
mov [eax], bx

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]

kumaresh_ana
October 10th, 2006, 01:57 AM
Is the assembler shows you error? Tell your problem.

mov ax, [eax]
mov bx, [ebx]
mov [ebx], ax
mov [eax], bx

What purpose do these serve you?


;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 ?

.code
begin:
lea eax,x
lea ebx,y

next:


push [eax]
push [eax+8]
push [eax+16]
push [eax+20]
push [eax+24]
push [eax+28]
push [eax+32]

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 ?

.code
begin:
lea eax,x
lea ebx,y

next:


push [eax]
push [eax+4]
push [eax+8]
push [eax+12]
push [eax+16]
push [eax+20]
push [eax+24]


pop [ebx]
pop [ebx+4]
pop [ebx+8]
pop [ebx+12]
pop [ebx+16]
pop [ebx+20]
pop [ebx+24]


i did offset of 4 and reverse the pop

kumaresh_ana
October 10th, 2006, 03:44 AM
Yes. BTW are you planning to assemble this or not?

horent135
October 11th, 2006, 12:17 AM
im getting this error msg.. dunno wat to do...

Linking...
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
C:\Documents and Settings\Racer\Desktop\temp\hw1.1\Debug\hw1.1.exe : fatal error LNK1120: 1 unresolved externals
hw1.1 - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========





include irvine32.inc

.data
X SDWORD -3000, -2000, -1000, 0, 1000, 2000, 3000
Y SDWORD 7 DUP (?)
Z SDWORD ?

.code
begin:
lea eax,x
lea ebx,y
lea edx,z
mov ecx,7

next:

;pushing x into a stack
push [eax]
add eax,4

;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.