Thursday, December 17, 2009

Diversions

When I realized my alignment problem yesterday, I thought about changing my design to save words, not individual bytes. The reason I'd chosen bytes in the first place, though, was to save an items of arbitrary size - 1 to 4 bytes - without padding. In principle, this would be scalable to objects of larger size.

I decided to try to save each byte in multiple byte numbers. Along with keeping my original design, this would allow me to practice some masking, shifting, and branching.

Some code:

LDR R2, =Heap_Mem ; temp just the Heap_Mem

ldr R3, =0xCCBBAA ; Set R3 to value
AND R4, R3, #0xFF ; Set R4 to R3 masked & 00000000000000000000000011111111 0xFF
STR R4, [R2] ; Save R4 to location R2

ADD R2, R2, #1 ; increment R2
CMPS R3, R4 ; compare R3 and R4
BEQ end_of_save ; if equal, jump to end_of_save

NOP

MOV R4, R3, LSL #16 ; Set R4 to R3 shifted left 16 bits
MOV R4, R4, LSR #24 ; Set R4 to R4 shifted right 24 bits
STR R4, [R2] ; Save R4 to location R2

ADD R2, R2, #1 ; increment R2

ldr R4, =0xFFFF ; Set R4 to FFFF
CMPS R4, R3 ; check whether R3 <>
THIS ISNT WORKING START HERE BMI end_of_save ; if so, jump to end_of_save

NOP

end_of_save


As you can see, I'm planning on walking all the way through the number, paring it down as I go. Yes, this could be a loop and if I was writing in C, I'd be confident enough to implement it that way. For now, just baby steps.

You'll notice the note to myself - I need to figure out conditionals. That's up first tomorrow.

Up second is, this hasn't overcome my alignment problem.

This code saves "aa" and then "bb" at the same memory location. Not sure why, yet.

No comments:

Post a Comment