Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: matthias1992 on July 11, 2010, 09:45:19 am

Title: ASM base adress [start adress] in hex
Post by: matthias1992 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?
Title: Re: ASM base adress [start adress] in hex
Post by: thepenguin77 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.
Title: Re: ASM base adress [start adress] in hex
Post by: calcdude84se 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"?
Title: Re: ASM base adress [start adress] in hex
Post by: thepenguin77 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.
Title: Re: ASM base adress [start adress] in hex
Post by: quasi_Phthalo 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.???
Title: Re: ASM base adress [start adress] in hex
Post by: DJ Omnimaga 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.
Title: Re: ASM base adress [start adress] in hex
Post by: quasi_Phthalo on July 12, 2010, 12:32:24 am
i stand corrected:
matthias, could you perhaps explain to us the purpose of this program?
Title: Re: ASM base adress [start adress] in hex
Post by: Quigibo 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.
Title: Re: ASM base adress [start adress] in hex
Post by: matthias1992 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
Title: Re: ASM base adress [start adress] in hex
Post by: DJ Omnimaga 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