Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: jwalker on April 28, 2012, 10:02:53 pm
-
So, I have started learning Z80 ASM again and I have a question...
In a user program, I know that the first two bytes are size bites, are the next 8 or less the name?, if it is is it null terminated.
Then say I wanted to get the first "line" of the program how would I do that, I've been doing some testing and it hasnt worked out( I think because of something in the first two lines of what I wrote).
-
In a user program, I know that the first two bytes are size bites, are the next 8 or less the name?, if it is is it null terminated.
Nope, the data comes right after the size bytes.
Variable names and flags aren't part of any variable except when it's archived. All that stuff goes in the VAT. (That's why if you have two VAT entries pointing to the same address, you can edit one variable and watch the other change too :D)
-
If you want to edit the first byte, you can try this:
ld hl,NAME
rst rMOV9TOOP1
bcall(_ChkFindSym)
ret c ;The program doesn't exist, so exit
ex de,hl
;Just checking to make sure the size isn't zero, otherwise it will edit unknown data
ld a,(hl)
inc hl
or (hl)
ret z
inc hl
ld (hl),30h ;or whatever byte you want
ret
NAME:
.db 5,"HELLO",0 ;5 means program, 0 terminates
If you want to see more complicated code that edits the first byte of the second line:
ld hl,NAME
rst rMOV9TOOP1
bcall(_ChkFindSym)
ret c
ex de,hl
;Just checking to make sure the size isn't zero, otherwise it will edit unknown data
ld c,(hl)
ld a,c
inc hl
or (hl)
ret z
ld b,(hl)
inc hl
;BC is now the size of the program
;HL points to the data
ld a,3Fh ;3Fh is the newline token
cpir ;Search a max of BC bytes at HL for the first instance of A
ret po ;No bytes left in the program
;HL now points to the byte after the start of the second line
;Make sure it isn't another newline. (means Line 2 was empty)
cp (hl)
ret z
ld (hl),30h ;or whatever byte you want
ret
NAME:
.db 5,"HELLO",0
-
Ok, It works so thanks