?

Log in

No account? Create an account
Hrmph. Victory, but no victory. - Chaz Meyers [entries|archive|friends|userinfo]
Chaz Meyers

[ website | chazmeyers.com ]
[ profile | view profile ]
[ archive | view archive ]

Links
[Links:| chazmeyers.com Twitter ]

Hrmph. Victory, but no victory. [Oct. 31st, 2002|12:29 am]
Chaz Meyers
Hmm. I got my lab for 72 to work, but rather than figure out what the problem was, I took an entirely different route and that is annoying me.

The problem was to reverse an array in place using assembler, creating a function that looks like:
revarray( int *a, int n); // a is an array of n elements

My initial logic was:
Calculate address of end of array and store. Basically end = a + (n-1)*4, since c ints are 4 bytes.
loop: Load int at beginning and end of array into 2 registers.
Store in opposite locations.
Increment the register storing the beginning of the array by 4, effectively chopping off the first element.
Deincrement the register storing the end of the array by 4, effectively chopping off the last element.
If the address of the begining is less than the address of the end, branch back to loop.

For some reason, whenever it would go through the loop the second time, it would give an access violation. I narrowed it down to something being fishy with the line:
S4SUBL R1, R24, R24 ; r24 is end of array register, r1 is 1.

As I wrote it up right here, I just thought of something. See, I know that:

s#add r1, r2, r3

does r3 = r1*# + r2. But in adding, order doesn't matter. I'm wondering if s#sub subtract do:
r3 = r1*# - r2 or
r3 = r2 - r1*#

Hrmph. I really need it to do the latter, but that would explain why it didn't work. The wording in the manual is fuzzy:
"The first operand is multiplied by # and subtracted to the second operand"
What the hell is "subtracted to"? Hrmph.

Anyway, I solved the problem by changing n and moving the first bit calculating the end into the loop and looping until the counter is less than or equal to 0. I was going to point out that I was really annoyed that I had to change my solution to get it to work, since I don't know what I did wrong.. now I'm wondering if I just misunderstood the manual. Hmm. I guess I'm going to need to learn to use the bloody debugger soon. Can't rely on commenting out random lines until you find what breaks.

Matrix multiplication will be interesting, since I always forget how to do that by hand. :-p
LinkReply

Comments:
[User Picture]From: bbfrombkln
2002-10-31 08:23 am (UTC)
So I just read your entire post, pretending to follow what you were saying. But I didn't. You were speaking in tongues. You geek, you! ;)

~Ben
(Reply) (Thread)
[User Picture]From: qsical
2002-10-31 10:12 am (UTC)
HAPPY HALLOWEEN!!
(Reply) (Thread)
From: julietbelle
2002-10-31 03:31 pm (UTC)

Hehehe

Happy Halloween.....also, in the C++ book, page 106, it goes through the entire debugging issue. Process of elimination, my dear:) What do you think I did when that one program just wasn't working?????

If all else fails, sleep on it (not literally) and you should wake up with a somewhat better understanding of the problem and/or how to fix it. Like that one time, I was up until midnight talking to you and then when I got up the next morning I changed things around and it worked...weird, but it worked, gosh darn:-P

Luv ya,
Holl
(Reply) (Thread)