Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: Munchor on April 12, 2011, 06:34:30 am
-
I have this code (in Mimas):
Start:
db $ef,$40,$45
ld b,100
ld a,0
Loop:
add a,myNum
djnz Loop
ld l,a
db $21,$01,$00
db $ef,$07,$45
B_CALL (_GetKey) ;ef4972
ret
myNum:
db 3
I'm trying to make a loop where I add 3 to a 100 times.
Will this ever work? I'm not sure if I can set variables like that or only by (myVar .equ 3).
Thanks.
-
Mimas=cool, huh? :)
You'll get 300-255=a 45 higher than the offset because the registers are 8-bits. I think this will work, you just should try it out.
-
aeTIos: That's not the problem, this won't work too, I think:
Start:
db $ef,$40,$45
ld b,100
ld a,0
Loop:
add a,myNum
djnz Loop
ld l,a
db $21,$01,$00
db $ef,$07,$45
B_CALL (_GetKey) ;ef4972
ret
myNum:
db 1
-
myNum isn't 1; it's a pointer to a byte that's one. In other words, you're adding something like 40,371 to A every pass.
EDIT: Quick explanation of pointers here (http://ourl.ca/9165/180882) if you're confused :)
-
You need to do add a,(myNum)
myNum is merely labeling the address at which the data is found. You then have to indirectly load the data from the address.
-
I don't think ADD A,(n) is valid...
You'll have to do LD HL,myNum \ ADD A,(HL).
-
Ah yes, you're right. My bad.
-
You can use ld a,(Address) instead of loading the address to HL first. :)
-
Just a question. Why are you doing in-line assembly in assembly? Why not just type out the bcall? It makes it easier for the non-xeda's to read :D
-
Also, if you want to do multiplication (I think that is what you want), you can use one of these routines:
http://wikiti.brandonw.net/index.php?title=Z80_Routines:Math:Multiplication
-
Just a question. Why are you doing in-line assembly in assembly? Why not just type out the bcall? It makes it easier for the non-xeda's to read :D
But easier for me to code, sorry.
add a,(mynum) Thanks, I actually though stuff inside parentheses were adresses and without parentheses were values. Is it different for variables??
-
You can use ld a,(Address) instead of loading the address to HL first. :)
It needs to be added to A, though.
add a,(mynum)
See my post above (http://ourl.ca/10330/197146) -- ADD A,(n) isn't valid.
Thanks, I actually though stuff inside parentheses were adresses and without parentheses were values. Is it different for variables??
That's exactly it. myNum is a pointer that points to a byte that has a value of 3.
I don't think you understand what "variables" are in ASM. In ASM, a "variable" is just a byte (or two bytes) of data reserved for a purpose. In this case, you use .db to reserve a byte that has a value of 3, and you label it as myNum -- the pointer of that byte.
-
This should work:
XOR A
LD H,0
LD B,100
Loop
INC A
DJNZ Loop
End
LD L,A
RST 28h
.dw DispHL
RET
This assumes that since MyVar is one, it can just use an increment sequence instead :)
-
You can use ld a,(Address) instead of loading the address to HL first. :)
It needs to be added to A, though.
add a,(mynum)
See my post above (http://ourl.ca/10330/197146) -- ADD A,(n) isn't valid.
Thanks, I actually though stuff inside parentheses were adresses and without parentheses were values. Is it different for variables??
That's exactly it. myNum is a pointer that points to a byte that has a value of 3.
I don't think you understand what "variables" are in ASM. In ASM, a "variable" is just a byte (or two bytes) of data reserved for a purpose. In this case, you use .db to reserve a byte that has a value of 3, and you label it as myNum -- the pointer of that byte.
That explained it all, thanks a lot.