gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > strb and strh

#11023 - jimmy-bucket - Tue Sep 23, 2003 6:32 pm

Hi all, ive been playing around with GBA asm for a while and I'm currently trying to plot pixels on the screen.

I did try using str, but it plotted one pixel, and set the ajacent one black, no good when overlayed over another line.

I'm using strb and it plots just the single pixel (or line of them) but turns the pixels a different colour. Here is the code:

Code:

@include screen.h
; Setup screen
ldr r1,=REG_DISPCNT
ldr r2,=(MODE_3|BG2_ENABLE)
str r2,[r1]
; red pixel, screen cordinates and amount
ldr r1,=0x00F
ldr r0,=VRAM+2410
ldr r10,=230
; draws a horizontal line
label2:
strh r1,[r0]+2!
subs r10, r10, 1
bne label2

ldr r0,=VRAM+2410
ldr r10,=150
; draws a vertical line but the colours are wrong
label1:
strb r1,[r0]+480!
subs r10, r10, 1
bne label1

infiniteloop
b infiniteloop


How can i have a single pixel of the same colour?

Thanks, Kieren

#11026 - DekuTree64 - Tue Sep 23, 2003 7:34 pm

Why are you using strh on the horizontal line and strb on the vertical? Pixels in mode3 are 2 bytes each, so just replace the strb on the vertical with strh and everything should be fine.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#11027 - jimmy-bucket - Tue Sep 23, 2003 7:39 pm

Thanks for the help, but that doesnt work... it returns an

Quote:
error : line 29 : operand size conflict
strh r1,[r0+480]!


error... i know i need to load 2 bytes of data, because its one pixel, but ldrh doesnt work!

#11036 - tepples - Wed Sep 24, 2003 12:04 am

I don't think [some of the load/store instructions] can be used with as many addressing modes as the others.

EDIT: I was wrong as to which were which.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.


Last edited by tepples on Thu Sep 25, 2003 1:38 am; edited 1 time in total

#11045 - torne - Wed Sep 24, 2003 11:20 am

The number '480' is too big to use as a preincrement in a strh instruction. You will have to restructure your code so that preincrements are not used or are smaller.

#11051 - jimmy-bucket - Wed Sep 24, 2003 6:16 pm

Yeah, I was playing arond with my syntax after I posted last night.

Code:
strh r1,[r0]
add r0, r0, 480


That seems to work, but I don't understand why a +480! writeback works with ldr and ldrb but not h.

Any suggestions?

Kieren

#11052 - DekuTree64 - Wed Sep 24, 2003 7:28 pm

ldr and ldrb are the same instruction, just with a different 'parameter', for byte or word, so you can use the same addressing modes with either of them. They allow a shifted register/shifted 8-bit immediate, so 480 is actually stored as 240<<1, because 240 fits in 8 bits. ldrh/ldrsh/ldrsb are all forms of the ldrh instruction, which is different than ldr, because there aren't enough bits in the ldr instruction to include all those variations. ldrh doesn't have a shift value, so you can only have immediate offsets that fit into 8 bits, and 480 doesn't.
So yeah, there's not much way of getting around doing a seperate add.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku