Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: ralphdspam on August 25, 2011, 09:06:44 pm
-
I saw the topic "Constructive and Creative uses of IX and IY," and I liked the idea of brainstorming creative uses for commands.
Two commands that always perplex me are RLD and RRD. I cannot think of many practical uses of them.
-
I use one of those in TI-Boy to emulate the SWAP (HL) instruction, which swaps the upper and lower nibbles of (HL).
It works like ld a,(hl) \ rrd.
-
As far as I can tell, the instructions are intended for use with BCD. They appear to allow multiplying and dividing by ten. Or sixteen, if you're using binary.
-
Indeed, the only time I've ever used it was for BCD. It's useful if you need to recover a number from TI's floating points. For instance:
turnTheEntireOp1ToADecimalStringRegardlessOfSignificateFigures:
ld hl, op1+2
ld c, 7
outerLoop:
ld b, 2
innerLoop:
ld a, $30
rld
ld (de), a
inc de
djnz innerLoop
inc hl
dec c
jr nz, outerLoop
xor a
ld (de), a
ret
-
I'm glad there are actually uses for that command. I like the idea of manipulating nibbles, but I don't like the fact that it modifies the source data. Can you use it on ROM code without any problems?
-
I'm glad there are actually uses for that command. I like the idea of manipulating nibbles, but I don't like the fact that it modifies the source data. Can you use it on ROM code without any problems?
You probably shouldn't be manipulating code by nibble :P Anyway, A contains the correct result even if (HL) can't be changed, IIRC.
-
/me uses OPTIMIZATION
turnTheEntireOp1ToADecimalStringRegardlessOfSignificateFigures:
ld hl, op1+2
ld b, 7
ld a, $30
loop:
rld
ld (de), a
inc de
rld
ld (de), a
inc de
inc hl
djnz loop
xor a
ld (de), a
ret
Edit:
Ooh, even better!
turnTheEntireOp1ToADecimalStringRegardlessOfSignificateFigures:
ld hl, op1+2
ld bc, 7
loop:
ld a, $33
rrd
ldi
ld (de), a
inc de
jp pe, loop
xor a
ld (de), a
ret
-
Ooh, rrd and rld are some of my favorite instructions! When I was describing what it does in my pocket asm tutorial was this:
rrd/rld the two nibbles from (hl) and the last nibble of 'a' make three nibbles. rrd
rotates them right and rld rotates them left.
As for a way to use them, I have a few codes that make excellent use of them. This one is from my program BSPRT. It uses hexadecimal sprite data, so instead of converting the hex string to a location in RAM and then copying it to the screen, I just did both at once (here is the sprite display part):
;Inputs:
; HL points to the buffer location to draw to
; DE points to the sprite data
ld bc,080Ch ;010C08
Loop:
call PutNibble ;CD****
call PutNibble ;CD****
ld a,b ;78
ld b,0 ;0600
add hl,bc ;09
ld b,a ;47
djnz Loop ;10F3
ret ;C9
PutNibble:
ld a,(de) ;1A
add $C0 ;C6C0
jr nc,$+4 ;3002
sub 7 ;D607
rld ;ED6F
inc de ;13
ret ;C9
This is my favorite one, though. When I made a graph shifting routine, I made these to shift 4 pixels very quickly:
ShiftLeft4:
ld hl,GraphBuf+767
ld c,64
xor a
ld b,12
rld
dec hl
djnz $-3
dec c
jr nz,$-9
ret
ShiftRight4:
ld hl,GraphBuf
ld c,64
xor a
ld b,12
rrd
inc hl
djnz $-3
dec c
jr nz,$-9
ret
I feel pretty proud of these :) I think the first can be optimised more, but it is still nice, I think :)
-
Unless i'm missing something, the first just says "Array", maybe you pasted the wrong thing?
-
It is because she wrote [code=something].
Here is what she meant :)
;Inputs:
; HL points to the buffer location to draw to
; DE points to the sprite data
ld bc,080Ch ;010C08
Loop:
call PutNibble ;CD****
call PutNibble ;CD****
ld a,b ;78
ld b,0 ;0600
add hl,bc ;09
ld b,a ;47
djnz Loop ;10F3
ret ;C9
PutNibble:
ld a,(de) ;1A
add $C0 ;C6C0
jr nc,$+4 ;3002
sub 7 ;D607
rld ;ED6F
inc de ;13
ret ;C9
-
Unless i'm missing something, the first just says "Array", maybe you pasted the wrong thing?
I am not seeing that... On mine, Hayleia and I have the same thing...
-
Unless i'm missing something, the first just says "Array", maybe you pasted the wrong thing?
I am not seeing that... On mine, Hayleia and I have the same thing...
??? I see "Array" too on yours. Maybe it depends on the browser.
But do you see "BSPRT" next to "code" ? (I don't see it, I had to quote you to see it should be here ;))
-
Well, it doesn't really matter now as i see what code you were talking about in Hayleia's post. Btw, what exactly do you mean by "hexidecimal sprites"? I'm trying to figure out what exactly your code does.
-
Ah, well with that code, will draw a sprite with hexadecimal data input. By that, I mean . db "3C4281818181423C" as opposed to .db 3Ch,42h,81h,81h,81h,81h,42h,3Ch
The first is what a TI-BASIC string would be like and the program that code is in is designed for TI-BASIC programmers to use.
-
Axe uses RRD and RLD for nibble storing. I've never used them anywhere else, they are definitely very uncommon. :ninja:
;hl = Nth nibble after address $8000
;e = Nibble to store there
NibSto:
scf
rr h
rr l
jr nc,__NibStoHigh
rrd
ld a,e
rld
ret
__NibStoHigh:
rld
ld a,e
rrd
ret
__NibStoEnd:
-
That is fairly similar to how I used it in BatLib for the nibble storing and retrieving.