Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Munchor on April 10, 2011, 05:19:15 am

Title: Variables and a/hl register
Post by: Munchor on April 10, 2011, 05:19:15 am
I have this code:

Code: [Select]
;Program made by: David Gomes

.nolist
#include "ti83plus.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:


    b_call(_ClrLCDFull)
        myVar .equ 60
ld a,myVar
ld h,0
ld l,a
b_call(_DispHL)
b_call(_GetKey)
    b_call(_ClrLCDFull)
res 5,(iy+0)             ; Disables 'Done' message
    ld    hl, 0
    ld    (PenCol), hl
    ld    hl, msg
    b_call(_PutS)            ; Display the text
    b_call(_NewLine)
    ret

msg:
    .db "Hello world!", 0
.end
.end

When compiling I get this:

Code: [Select]
Pass one...
myfile.z80:11: warning: Suggest remove extra parentheses around argument
myfile.z80:12: error: Can't recognize 'myVar' as an instruction or macro
myfile.z80:16: warning: Suggest remove extra parentheses around argument
myfile.z80:17: warning: Suggest remove extra parentheses around argument
myfile.z80:18: warning: Suggest remove extra parentheses around argument
myfile.z80:23: warning: Suggest remove extra parentheses around argument
myfile.z80:24: warning: Suggest remove extra parentheses around argument
Pass two...
myfile.z80:13: error: 'myVar' isn't a macro or label
Done

It's supposed to display the number 60 and then after a keypress display "Hello World!". What am I doing wrong with myVar here?
Title: Re: Variables and a/hl register
Post by: Ashbad on April 10, 2011, 09:09:30 am
The assembly itself is correct, but the stuff the assembler deals with otherwise is not.  To declare myvar, there cannot be an indentation first, otherwise it reads as a non-real instruction.  Secondly, you are being warned to put ending parenthesis on those bcall macros -- you don't have to since its just a warning, but you can believe me it's good practice.  Here is working code:

Code: [Select]
;Program made by: David Gomes

.nolist
#include "ti83plus.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:


    b_call(_ClrLCDFull)
    myVar .equ 60
ld a,myVar
ld h,0
ld l,a
b_call(_DispHL)
b_call(_GetKey)
    b_call(_ClrLCDFull)
res 5,(iy+0)             ; Disables 'Done' message
    ld    hl, 0
    ld    (PenCol), hl
    ld    hl, msg
    b_call(_PutS)            ; Display the text
    b_call(_NewLine)
    ret

msg:
    .db "Hello world!", 0
.end
.end
Title: Re: Variables and a/hl register
Post by: Munchor on April 10, 2011, 09:13:30 am
Ashbad, I still get this:

Code: [Select]
Pass one...
myfile.z80:9: warning: Suggest remove extra parentheses around argument
myfile.z80:10: error: Can't recognize 'myVar' as an instruction or macro
myfile.z80:14: warning: Suggest remove extra parentheses around argument
myfile.z80:15: warning: Suggest remove extra parentheses around argument
myfile.z80:16: warning: Suggest remove extra parentheses around argument
myfile.z80:21: warning: Suggest remove extra parentheses around argument
myfile.z80:22: warning: Suggest remove extra parentheses around argument
Pass two...
myfile.z80:11: error: 'myVar' isn't a macro or label
Done

When I run it, it displays 0 and then "Hello World!".
Title: Re: Variables and a/hl register
Post by: Ashbad on April 10, 2011, 09:32:00 am
Try unindenting my var completely then :)

Edit: and for all of those double indented bcalls, you should also make sure they're only indented once -- consistency is key :)
Title: Re: Variables and a/hl register
Post by: Munchor on April 10, 2011, 09:34:10 am
Try unindenting my var completely then :)

Awesome.

I didn't know assemblers cared about tabs and space only line breaks (I thought).
Title: Re: Variables and a/hl register
Post by: jnesselr on April 10, 2011, 10:52:28 am
also, don't define a variable in the middle of the program, as it is compiled there, IIRC.  so do this:
Code: [Select]
;Program made by: David Gomes

.nolist
#include "ti83plus.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
    b_call(_ClrLCDFull)
    ld a,myVar
    ld h,0
    ld l,a
    b_call(_DispHL)
    b_call(_GetKey)
    b_call(_ClrLCDFull)
    res 5,(iy+0)             ; Disables 'Done' message
    ld    hl, 0
    ld    (PenCol), hl
    ld    hl, msg
    b_call(_PutS)            ; Display the text
    b_call(_NewLine)
    ret

msg:
    .db "Hello world!", 0
myVar .equ 60
.end
.end

Just use tabs, not spaces, btw.
Title: Re: Variables and a/hl register
Post by: Munchor on April 10, 2011, 11:03:31 am
Thanks graphmastur (for the tip)!