Author Topic: Assembly/Hexadecimal Questions  (Read 8047 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Assembly/Hexadecimal Questions
« on: December 28, 2010, 10:23:59 am »
To help me with my disassembler which has lots of instructions working already, but a few not working, I decided to create this post in order to get help, otherwise I'd go  :crazy:.

These are my Assembly and Hexadecimal Assembly questions.

QUESTION 1:According to the table here, [22] is:

Code: [Select]
ld (**),hl
In Assembly I'dd just:

Code: [Select]
ld (12),hl
But how should I do that in Hexadecimal?

QUESTION 2

Code: [Select]
ld hl,(**)
The same doubt as above but for [2A].

QUESTION 3

Since I'm coding a Disassembler, how should I handle bytes like [CB], [DD], [ED],[EF]? These link to other tables.



Thanks much for the help!

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: Assembly/Hexadecimal Questions
« Reply #1 on: December 28, 2010, 01:09:28 pm »
 would say for the link to other tables it would be something like:
Code: [Select]
If (byte==[ab])
{
 then do checks for other table
}
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Assembly/Hexadecimal Questions
« Reply #2 on: December 28, 2010, 01:28:48 pm »
would say for the link to other tables it would be something like:
Code: [Select]
If (byte==[ab])
{
 then do checks for other table
}

Yeah, I'll probably do that.

But the opcode [CB] is for the BIT Table. How would I know each one IN the other table?

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Assembly/Hexadecimal Questions
« Reply #3 on: December 28, 2010, 01:34:14 pm »
not sure, but it appears that * = one byte value and ** = two byte value.

so ld (12), hl would be 22000C right?
edit: or maybe its 220C00, because z80 is little endian.

it'd be a good idea to compile an axe program with:
Code: [Select]
.TEST
12
and see what comes out with this
« Last Edit: December 28, 2010, 01:42:53 pm by nemo »


Offline AssemblyBandit

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 374
  • Rating: +60/-1
  • ~AssemblyBandit~
    • View Profile
    • briandm82.com
Re: Assembly/Hexadecimal Questions
« Reply #4 on: December 28, 2010, 07:47:09 pm »
ld (**),hl loads hl into a specific 2 byte address. Generally you would use it like ld (score),hl and that would copy your value in hl into your address with the label score.

$dd (ix) and $fd (iy) always precede $cb (bit) or $ed (ext) if present,  followed by the index offset if needed, followed by the instruction. So first you should always check for a $dd or $fd and you would know that you were dealing with an index.

Tomorrow Ill give you the code for my disassembler and that should help you out a bit.

ret = $c9
ld ($9d95),hl = $22 $95 $9d
ld hl,($9d95) = $2a $95 $9d
sbc hl,bc = $ed $42
lbit 1,a,(ix+3) = $dd $cb $03 $4f           (this is the way I have the mnemonic set up in my table but the opcode is the same.)

For bit instructions you can just multiply the bit by 8 and add it to the regular opcode.

bit 0,a = $cb $47
bit 1,a = $cb $4f ($47+bit*8 )
« Last Edit: December 28, 2010, 07:52:29 pm by AssemblyBandit »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Assembly/Hexadecimal Questions
« Reply #5 on: December 29, 2010, 05:56:18 am »
Thanks much AssemblyBandit. Are you like the Assembly bandit (literally?).

Anyways, my disassembler already has the primary instructions finished and half of the extended instructioons.

It looks like in some opcodes, the numbers are in the middle of it and some of them are in the end, that's wow confusing :S

Quote
bit 0,a = $cb $47
bit 1,a = $cb $4f ($47+bit*8 )

EDIT: Thank you Very much for this piece of code. I have finished Extended Instructions and am now including Bit Instructions, then off I go to IX and IY.

New Question...

inc (ix+*)   
dec (ix+*)
ld (ix+*),*

How would these be used in Hexadecimal?

res 6,(ix+*),l

This one too xD

Thanks much, probably the last Hexadecimal question for my program :D
« Last Edit: December 29, 2010, 11:39:29 am by ScoutDavid »

Offline AssemblyBandit

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 374
  • Rating: +60/-1
  • ~AssemblyBandit~
    • View Profile
    • briandm82.com
Re: Assembly/Hexadecimal Questions
« Reply #6 on: December 30, 2010, 12:11:49 am »
inc (hl)
$34

inc (ix+3)   
$dd $34 $03

dec (hl)
$35

dec (ix+4)
$dd $35 $04

ld (hl),10
$36 $0a

ld (ix+2),10
$dd $36 $02 $0a
^    ^   ^   ^
|     |    |   value to be loaded
|     |    ix index offset
|     actual opcode
ix identifier

Notice youre basically just putting $dd or $fd in front of the equivalent instruction that uses hl and following the opcode with the index offset.

res 0,(ix+1)
$dd $cb $01 $86
                   ^basically just like the other bit instructions, just use the opcode at 0, multiply the bit by 8 and add it to the opcode.

res 6,(ix+1)
$dd $cb $01 $b6
                   ^$86 + 6 * 8 = $b6



One thing thats really useful in a disassembler is having it automatically label rom calls, ram locations, ports, flags, and restarts. Basically just try to have it match any address to one in a rom call table for instructions that use them and do something similar for the ports, ram locations, flags, and restarts.

This is an example of what mine puts into a text file:

0A3E   LD   A,$06
0A40   OUT  ($04),A   ;Power Mode Port
0A42   LD   A,$11
0A44   OUT  ($03),A   ;Interrupt Mode Port
0A46   RES  3,(IY+$12)   ;?indic,shift flags?
0A4A   RES  3,(IY+$09)   ;?on flags?
0A4E   EX   AF,AF'
0A4F   EXX
0A50   EI
0A51   HALT

It puts the extra info into comments at the end of the instructions. Note that this is part of the ti-84's rom, but I made the disassembler for the ti-86 and I havent updated any of the tables. (Its still pretty close though.)
« Last Edit: December 30, 2010, 12:41:45 am by AssemblyBandit »

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: Assembly/Hexadecimal Questions
« Reply #7 on: December 30, 2010, 12:21:45 pm »
Woah your assembler even generates comments? O.O This is pretty cool actually. You should make it for the 83+/84+ and post it. :O

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Assembly/Hexadecimal Questions
« Reply #8 on: December 30, 2010, 05:15:10 pm »
Woah your assembler even generates comments? O.O This is pretty cool actually. You should make it for the 83+/84+ and post it. :O

You can make comments on mine too :D

In my program, concerning Assembly and program itself (not GUI and extras), all that's left is add BCALLs:

http://brandonw.net/calcstuff/page0.txt

Any useful advice AssemblyBandit? Your code examples were really good, but I had already figured them out by the time I saw them.

Oh! There's another thing missing: Reading .8xp files data :S

Offline AssemblyBandit

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 374
  • Rating: +60/-1
  • ~AssemblyBandit~
    • View Profile
    • briandm82.com
Re: Assembly/Hexadecimal Questions
« Reply #9 on: December 30, 2010, 07:02:09 pm »
Ill edit everything to work with the 83+/84+ but the code is pretty embarrassing, I should have it done by tonight. Ill post some code to read 8xp data in a little bit. I originally used VC++ but I might rewrite it in VB.

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: Assembly/Hexadecimal Questions
« Reply #10 on: December 31, 2010, 03:14:22 am »
Cool :D

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Assembly/Hexadecimal Questions
« Reply #11 on: December 31, 2010, 11:53:58 am »
I have wrote this file with lots of BCall's, any idea if these will be enough?