Author Topic: Variables and a/hl register  (Read 4384 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Variables and a/hl register
« 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?

Ashbad

  • Guest
Re: Variables and a/hl register
« Reply #1 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

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Variables and a/hl register
« Reply #2 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!".

Ashbad

  • Guest
Re: Variables and a/hl register
« Reply #3 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 :)
« Last Edit: April 10, 2011, 09:35:09 am by Ashbad »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Variables and a/hl register
« Reply #4 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).

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Variables and a/hl register
« Reply #5 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.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Variables and a/hl register
« Reply #6 on: April 10, 2011, 11:03:31 am »
Thanks graphmastur (for the tip)!