# assembly language

Discussion in 'All Other Software' started by martin65, Nov 12, 2007.

Not open for further replies.

Joined:
Jan 7, 2006
Messages:
20
Hello!
I've started working with assembly language, with simulator LC-2, for a while!
now I'm trying to write a program that multiplies a number by -6 . I've got the right code for multiplying it by 6, and then I was trying to inverse the sign of the result of that to get the answer if it was multiplied by -6. so I did the same code as if its multiplied by 6, and then the final result of that was stored in register R3, so to get the result of multiplying the same number with -6, I was trying to get the negative of R3 so I wrote: NOT R3, R3 which means NOT R3 and store the result in itself! so say my number was 4 and I wanted 4x-6=-24, so I got 24 and then inverted its sign to get -24 but then simulating this in LC-2 gave me -25 !!!
do u know why? and what do I have 2 do 2 fix it??
aside: by the way do u know whats -6 in hexadecimal?

regards....

2. ### jstoneky

Joined:
Oct 25, 2007
Messages:
17
I don't know anything about lc-2 really, but using assist when you multiply using registers, it gives a 2 register answer, so lets say you want to multiply something, you need an even-odd pair of registers available to do so. If you want to multiply A by B, You Load A into register 3, and say B in register 4.

when you do
MR 2,4
You are actually multiplying register 3 by register 4, and storing the result in register 2 and 3. so if A = 2 and B =2
register 2 = 00000000
and register 3 = 00000004

as for your coding, I would just compare the register that would possibly have -6, to -6, and if it indeed is -6, multiply your answer by -1.

hex -6 is FFFF FFFA

As Seen On