Author Topic: ASM base adress [start adress] in hex  (Read 4619 times)

0 Members and 1 Guest are viewing this topic.

Offline matthias1992

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 408
  • Rating: +33/-5
    • View Profile
ASM base adress [start adress] in hex
« on: July 11, 2010, 09:45:19 am »
(How) can I write in hex were the program starts?
In normal asm you'd type
Code: [Select]
.org $9D95
but can you define this in hex? or does it depend on the name of the program or how full your memory is? I want to know my base adress because otherwise it is merely impossible to write JP's, JR's and CALL's in hex, and they are quite neccesary...

for example this program:
Code: [Select]
A:
    .db %11111111
B:
     call a
ret
converts to this:
Code: [Select]
FFCD9D95C9
and then to this(??(on second on-calc compilation)):
Code: [Select]
FFCD9893C9
so clearly the base adress changes once I compiled a second time...So I need to determine where in memory the prgm must reside otherwise jumps are impossible to code in hex (and they are quite complicated already because you need to count the bytes from base up to a label)

EDIT:
maybe storing PC helps? altough there is no direct way to do so. Maybe you could force PC to be pushed on the stack and then pop it into variable? however wouldn't that very action influence PC and corrupt it?
Anyone any ideas on how to do this?
« Last Edit: July 11, 2010, 09:56:10 am by matthias1992 »
MASM xxxxxxxxxx aborted | SADce ====:::::: 40% -Halted until further notice| XAOS =====::::: 50% -Units done| SKYBOX2D engine ========== 100% -Pre-alpha done. Need to  document it and extend |

~Those who dream by day are cognizant of much more than those who dream by night only. -Sir Edgar Allen Poe-

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: ASM base adress [start adress] in hex
« Reply #1 on: July 11, 2010, 02:37:17 pm »
I'm not sure what you mean by the second compilation. But you just type the address in after the call function. So the first example would be, FF CD 95 9D C9. You had your address backwards. You have to remember that it is little endian, meaning that the least significant part of the address comes first. 9D95 is stored as 95 9D, 123456 is stored as 56 34 12.

It might be easier to try to stick with relative addressing, jr, because you just count how many spaces you want to go from the next byte. So if you want to loop endlessly you would write jr -2, or 18 FE.

To use absolute addressing, call and jp, you will have to keep track of sp through your program, this gets really annoying when you start adding stuff and you have to go change all your calls and jps.

You also don't need to define your starting location, .org. You only have to do this in TASM because TASM doesn't know where you are starting. Maybe you're writing an app and starting at 4000, or an OS starting at 0000. You mentally write the .org in your hex program because you have to do all the adding yourself.

The only way to push pc is to do a call.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: ASM base adress [start adress] in hex
« Reply #2 on: July 11, 2010, 06:04:05 pm »
To use absolute addressing, call and jp, you will have to keep track of sp through your program, this gets really annoying when you start adding stuff and you have to go change all your calls and jps.
you mean pc, not sp, right? You should never have to keep track of sp :P

The only way to push pc is to do a call.
Very true. If you for some reason need to know the pc, you have to have a routine at a known location in RAM containing "pop hl \ jp (hl)" No dynamic way to do it.

matthias1992: could you explain what you mean by "second on-calc compilation"?
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: ASM base adress [start adress] in hex
« Reply #3 on: July 11, 2010, 06:21:42 pm »
To use absolute addressing, call and jp, you will have to keep track of sp through your program, this gets really annoying when you start adding stuff and you have to go change all your calls and jps.
you mean pc, not sp, right? You should never have to keep track of sp :P

Idk why, but in my mind, I use sp and pc interchangeably. Yes, pc.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: ASM base adress [start adress] in hex
« Reply #4 on: July 12, 2010, 12:21:45 am »
the calc ALWAYS loads the program so that the start of the executable part is at $9D95 --it doesn't matter where the program is stored when not in use

i know that you don't mean you're running AsmComp( twice because the calc doesn't let you do that; and even after you've done it once, you can't read the hex code anymore unless you have an emulator; also i tried that on an emulator and i can't replicate it. are you using a faulty on-calc assembler like the (unfinished) Chasm? as for $9893 / $9398, they are parts of appBackupScreen and PlotSScreen respectively. there's no reason why a program would call that unless you've manually loaded code there.

also, why would you want a program like that one? it just overflows the stack and crashes the calc.???

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: ASM base adress [start adress] in hex
« Reply #5 on: July 12, 2010, 12:26:17 am »
Quasi_Phthalo: Maybe he had something else in mind. We have to stay open-minded on the fact people may be experimenting with unconventional tricks to attempt something not done before on calcs. This is how people came up with Ndless, TI-Boy SE, OSKill, F-Zero 83+, Axe Parser, etc. If we stuck to the "Why-do-you-want-to-do-that-It-will-not-work" logic, those programs would never have come out. In fact, people back then stuck to that logic, to never try anything new because it was not "normal programming" and we had to wait 10 years before Axe Parser and Calc84maniac/BrandonW stuff arrives on our machine.

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: ASM base adress [start adress] in hex
« Reply #6 on: July 12, 2010, 12:32:24 am »
i stand corrected:
matthias, could you perhaps explain to us the purpose of this program?

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: ASM base adress [start adress] in hex
« Reply #7 on: July 12, 2010, 12:45:20 am »
First of all, matthias1992 I can tell you're new to assembly.  The .org is an organization command that keeps track of what to make the jumps, calls, and labels.  If you had .org $9D95 and in your code you were jumping to a label which was $20 bytes past your .org statement, the assembler would know to make the jump address at $9D95 + $20 = $9DB5.  The .org statement itself does not contribute anything to the code, rather it is a command to tell the assembler what to add for each label.  I don't know what compiler you are using, but at this point in time, computer compilers are the only reliable way to compile assembly language programs.  However there are some promising projects in the works.

DJ, quasi_Phthalo was referring to the example code matthias1992 posted which would be like in BASIC: Lbl A:While 1:GotoA:End which just causes a stack overflow and crash.  There isn't really any exploit you would use this for so he is right in questioning his intentions.  I think he just misunderstood that this is just some example code to help explain what he is talking about and not an actual program.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline matthias1992

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 408
  • Rating: +33/-5
    • View Profile
Re: ASM base adress [start adress] in hex
« Reply #8 on: July 12, 2010, 09:31:55 am »
OK so if I am right then you just can assume that it resides/starts at $9D95 right?
so then you'd only need to keep track of the bytes every command takes and thus determine at which byte each label is....

correct me if I am wrong. Ooh and indeed the program has no actual use (It crashes) it was for demonstration purposes only
« Last Edit: July 12, 2010, 02:05:11 pm by matthias1992 »
MASM xxxxxxxxxx aborted | SADce ====:::::: 40% -Halted until further notice| XAOS =====::::: 50% -Units done| SKYBOX2D engine ========== 100% -Pre-alpha done. Need to  document it and extend |

~Those who dream by day are cognizant of much more than those who dream by night only. -Sir Edgar Allen Poe-

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: ASM base adress [start adress] in hex
« Reply #9 on: July 12, 2010, 12:27:19 pm »
Aaah I see, I do not know ASM so I did not realize the code wasn't doing anything. I kinda assumed he was experimenting with something and/or that he did not post his entire source code