Author Topic: need code to get the address in hexadecimal (code in basic)  (Read 2626 times)

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
For people who knows how hexadecimal programing works, and ti basic language,
So I'm trying to create a on-calc assembler, and i need code to get the address in hexadecimal? (i already have a basic prgm that will convert number in a (decimal) to hexadecimal,prgm that will change letters to hexadecimal) i just cant figure out how it works. i read the code from OTBP, TASM again and again, but i coudnt figure out how they get it.
for example,

ld hl,0h                   ;210000
ld (currow),hl           ;224B48
ld hl,text                 ;21A29D this is the part i dont know how to get
bcall puts                ;EF0A45
ret                          ;c9
text:                       ;48454C4C4F20574F524C442100
.db "hello world",0
i know that prgm starts at $9D95 ($959D)
Please help!
if this is too much, you can still give me some tips to do this. thanks
« Last Edit: May 27, 2011, 04:45:53 pm by TiAddict »

SirCmpwn

  • Guest
Re: need code to get the address in hexadecimal (code in basic)
« Reply #1 on: May 28, 2011, 06:43:01 pm »
Okay, so you need to keep track of the address as you're assembling.  Here's how I would do it with your program: perform two passes, and keep track of everything you need to know an address for.  Like this:
Code: [Select]
ld hl,0h                   ;9D95: 210000
ld (currow),hl           ;9D98: 224B48  (plus 3 bytes to current address)
ld hl,text                 ;9D9B: 210000  (default the value to 0000, and store the word "text" somewhere, and the address 9D9B)
bcall puts                ;9D9E: EF0A45
ret                          ;9DA1: c9
text:                       ;9DA2 (save this somewhere - text = 9DA2)
.db "hello world",0 ;48454C4C4F20574F524C442100
Then, go find everywhere that mentions "text" and replace the value with A29D (don't forget little endian)

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: need code to get the address in hexadecimal (code in basic)
« Reply #2 on: May 29, 2011, 01:35:42 am »
Ah thank you! that explained so much! ahaha :) but what should i do if there is more address to save? that i will need more strings right? or is there a way to store in a list?

and does using "Ans" faster?
for example,
:1+1->A
or
:1
:Ans+1->A

SirCmpwn

  • Guest
Re: need code to get the address in hexadecimal (code in basic)
« Reply #3 on: May 29, 2011, 01:44:49 am »
Using ans is tricky and requires careful planning of the whole program.  For something as complex as an assembler, I would stick to variables.  As for strings, I suggest using a combination of a list, a string, and sub(.  For example, with the text label and an example label, the string could be "testexample" and the list could contain the starting position and length of each labels name, and the address they represent.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: need code to get the address in hexadecimal (code in basic)
« Reply #4 on: May 29, 2011, 01:48:57 am »
oh I see. Thank you so much for helping! :D

SirCmpwn

  • Guest
Re: need code to get the address in hexadecimal (code in basic)
« Reply #5 on: May 29, 2011, 01:53:30 am »
Sure thing.  Be sure to post any other troubles you encounter, and watch for an upcoming tutorial of mine on the subject.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: need code to get the address in hexadecimal (code in basic)
« Reply #6 on: May 29, 2011, 11:43:00 pm »
oh thank you :D and i will! i cant wait!