Author Topic: Coding ASM by hand  (Read 14067 times)

0 Members and 3 Guests are viewing this topic.

Offline matthias1992

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 408
  • Rating: +33/-5
    • View Profile
Coding ASM by hand
« on: July 11, 2010, 07:22:45 am »
EDIT2: Seemingly my explanation is not really comprehensible because this topic has been viewed alot but 0 downloads so far...
or: is there simply no intrest in this? tell me!

One of the most difficult aspects of asm is its final output. it is just a sheer list of hexadecimal characters. There are some on calc converters that allow you to write ASM but they compile slow and are slow to write in unless you can type blindfolded on your calc. I never tried to code directly in hex but yesterday was my first try and it went suprisingly good! One problem was in looking up all the hexadecimal codes for the commands (i try to avoid bcalls altough they are pretty easy in hex).

So I wrote a program that could look up commands for me. Currently I have a 382 byte string that contains the first 20 commands of TASM80.TAB
It works as follows. It looks up the command in str0 and outputs the correct hex format. BCALL's are yet unsupported since the hex digits are swapped and well..I just ahve not included that yet. If one were to include all the commands into str0 (no bcalls, only the commands) it would take up about 6KB. However not every command is really needed/ a lot used so currently I am writing a Limited instruction set into str0 that has all the basic asm commands. If you however wanted to add a command you'd only need to typ '^' into MASM (that is what my program is called).

Well enough talk lets get down to the action:
Before you boot up make sure you have string 0 declared, if you don't use the supplied string in the attachments just store something like ":" to it.'

As you boot up MASM you get a Command Line Interface (that is a pretty glamourous description of the Input command but enver mind). You can do 4 things from here.

Q              | quits
C              | clears string0
^              | Add a command to the library
[command] | outputs the hexadecimal code for [command]

Q and C are pretty obvious but '^' isnt. Whenever you add a command you are prompted 'C:' and 'H:'.  Make sure you open up TASM80.TAB or something else, just don't make mistakes in the input...some errors are catched but a wrong hexadecimal code might eventually crash your calculator.

C: [type number here][type command here]
H: [type hex equivalent here. lenght of this must be equal to "[type number here]"]

the command is now added to the library (aka string0)
lets for example add the command EX DE,HL

Tasm80.tab says this: EX   DE,HL   EB   1 NOP 1

There are two ways to deduce the number you need to type BEFORE the command. 1 way is to multiply the number BEFORE "NOP" (or ZIX sometimes) by 2. In this case 1*2 = 2 so the number would be 2. The second method is to look at the hex-code. in this case EB = 2 characters long. I highly recommend the first method because sometimes with commands with * in it (which means something like: fill in the blanks with a hexadecimal code of a number).Now we type the command:

C:2EX DE,HL

hit [ENTER]

then the hex equivalent:

H:EB

hit [ENTER]

So now the command EX DE,HL is added to the library. We can now recall the hex code for it by typing:

EX DE,HL

which will print

EB

BCALLS use the following syntax:

EF[last two digits][first two digits]

ClrLCDFull for example = 4540h

in hex that would be:

EF4045

This program is to be a digital replacement for TI83PLUS.INC (not yet) and TASM80.tab
I consider making an app out of it eventually to avoid the use of str0. For the moment however this program must be seen as a quick and easy lookup for Z80 commands.

Feedback and critique are welcome but just remember this is a unoptimized, pre-alpha and around midnight created program which lacks optimization.

EDIT: I think AXE is just perfect for this. it allows to insert large amounts of data without using user ram and it allows me to output to an app. I think I'll have to learn axe then....
« Last Edit: July 11, 2010, 09:32:13 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 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: Coding ASM by hand
« Reply #1 on: July 11, 2010, 12:46:16 pm »
I am confused at what is the purpose of this program. Do you just type an hex code then it converts to z80 ASM code? The explanation was a bit TL;DR so I skimmed through it :S

It would be nice to be able to easily convert z80 to hex or vice-versa, command by command, if possible, for easier insertion in Axe or Omnicalc stuff

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Coding ASM by hand
« Reply #2 on: July 11, 2010, 05:07:59 pm »
So, what I get of this: (correct me if I'm wrong)
You're trying to write a pure BASIC program that functions as a quick way to look up the hex for a command so you can code ASM on-calc. (Or are you trying to write a compiler?) You're considering making it in Axe.
And what I have to say:
That sounds interesting. I took the approach of just printing off the hex corresponding to each command, but it sounds like you want it entirely on-calc.
As for bcalls, little-endianness (this is what the phenomenon you're referring to is called) is an inherent property of the z80, and this is true for all commands like "ld hl,nn" or "ld (nn),a", basically any command where a two-byte number is directly in the code.

Whatever you're trying to do, good luck! ;D
"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 matthias1992

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 408
  • Rating: +33/-5
    • View Profile
Re: Coding ASM by hand
« Reply #3 on: July 11, 2010, 05:53:38 pm »
you input z80 asm and you get hex codes. Next step is to make a fully functional and automatic compiler. I need that tutorial on Axe really...
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 calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Coding ASM by hand
« Reply #4 on: July 11, 2010, 06:19:08 pm »
ah, okay. So you're going to write something like the OTBP assembler in the end?
(At this point you'll want to use Axe, and then we'll eventually have on-calc ASM compilers in three languages: OTBP in basic, MASM in Axe, and Mosaic in ASM. That'll be awesome! :D)
"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 TC01

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 344
  • Rating: +9/-0
    • View Profile
Re: Coding ASM by hand
« Reply #5 on: July 11, 2010, 06:26:19 pm »
ah, okay. So you're going to write something like the OTBP assembler in the end?
(At this point you'll want to use Axe, and then we'll eventually have on-calc ASM compilers in three languages: OTBP in basic, MASM in Axe, and Mosaic in ASM. That'll be awesome! :D)

And Tasm_on_calc and Chasm, among others... They look like they're written in assembly (that is, from their file category on ticalc.org), but I took a look at the Tasm_on_calc source once and it appears to be Basic with random assembly mixed in. Whereas ChAsm is definitely assembly.



The userbars in my sig are links embedded links.

And in addition to calculator (and Python!) stuff, I mod Civilization 4 (frequently with Python).

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Coding ASM by hand
« Reply #6 on: July 11, 2010, 06:32:37 pm »
Sorry, I never heard of those... Unfortunately, though, Chasm was never completed (and jr and djnz are, at least IMO, very important and necessary). I will look at Tasm_on_calc though, since it seems to be about equal to OTBP.
"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 TC01

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 344
  • Rating: +9/-0
    • View Profile
Re: Coding ASM by hand
« Reply #7 on: July 11, 2010, 06:56:01 pm »
Sorry, I never heard of those... Unfortunately, though, Chasm was never completed (and jr and djnz are, at least IMO, very important and necessary). I will look at Tasm_on_calc though, since it seems to be about equal to OTBP.
Hmm, it looks like Tasm_on_calc doesn't support relative addressing either.

So OTBP Assembler appears to be the best on-calc assembler currently available.



The userbars in my sig are links embedded links.

And in addition to calculator (and Python!) stuff, I mod Civilization 4 (frequently with Python).

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: Coding ASM by hand
« Reply #8 on: July 11, 2010, 07:37:07 pm »
So this is written in Axe?

That said, I would like such program since it's annoying when you know ASM to have to compile in 8xp, upload to Galandros unsquisher site then figure out what hex to keep and what not.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Coding ASM by hand
« Reply #9 on: July 11, 2010, 07:40:52 pm »
No, it's currently written in BASIC, but he wants to have it in Axe instead.
My statements of the possible awesomeness of this assume he will do it in Axe. ;D
"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 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: Coding ASM by hand
« Reply #10 on: July 11, 2010, 07:48:50 pm »
Oooh ok ^^

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Coding ASM by hand
« Reply #11 on: July 12, 2010, 08:03:43 am »
I always check new stuff, and this does certainly seem to be an interesting endeavor. However, I do not code in ASM, thus there is no reason for me to download it. It'll be cool to see it in action once you get it to a more useable state. ^^

Offline matthias1992

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 408
  • Rating: +33/-5
    • View Profile
Re: Coding ASM by hand
« Reply #12 on: July 12, 2010, 09:27:14 am »
I used tasm_on_calc which inspired me to do this but it is slow and has some bugs. Also coding in the basic editor goes slow and you easily make mistakes. If i could only figure out how to insert tokens...
« Last Edit: July 12, 2010, 09:29:37 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 Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Coding ASM by hand
« Reply #13 on: July 18, 2010, 11:06:26 pm »
Yeah, IMO OTBP is better than Tasm_on_Calc. I don't think the second ever got finished, and it's slower to program in (you have to add brackets to commands), and it compiles slower, too.

Can't wait for Mosaic (or this, too) :P




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: Coding ASM by hand
« Reply #14 on: July 18, 2010, 11:14:16 pm »
I also remember something called Mon, but it was very slow as well. I think it took 2 minutes to compile Hello World x.x