68000 assembler (building one that is)
Hello, im buoilding a basic (if you could call it that), 68000 assembler. Im so far successfully able to assemble a MOVE instruction based on the guidlines found in any 68000 manual
The main problem i have at the moment is implementing the ASSEMBLY of branching labels (and labels as operands) into the assembler part of my program.
The way my program works is that it assembles an instruction, say the MOVE instruction thus:
Code:
MOVE $7999,D1 = 32387999 (assembled instruction)
With 68000 instructions having variable sizes, this instruction would take up 4 bytes in memory. This would then be placed in my simulated memory, (im doin this by creating what ive called a memory structure):
Code:
typedef struct Memory{
char MNUM[XX] = MOVE
char Op1[XX] = $7999
char Op1[XX] = D1
.
.
.
.
.
char final_assembled[XX] = 32387999
Size_of_final_assembled = 4 bytes // Worked out by a simple
// strlen along the way
int start_mem = 0x0000002A // the amount of space the
int finish_mem = 0x0000002E // instruction takes up
struct Memory_Node *nextNode; // next node in memory starting a 0x0000002E
} Memory_Node;
Memory would be seen as a series of structures each linking to the next logical area to the next with a giving instruciton in the correct place of each node.
Braching instructions (like any othe 68k assembly instruction) also have varying sizes.
These sizes are worked out by taking the destination address (in memory) of the branch away from the source address (in memory) of the branch (then having an extra 2 taken aaway.) Below shows this:
Code:
########################################
0000002E 32387999 TEST: MOVE $7999,D1
00000032 32387999 MOVE $7999,D1 ' DEST COME FROM = RESULT (WORD)
00000036 60F6 BRA TEST ' 0000002E - 00000036 - 2 = F6 (from 60F6)
########################################
MEMORY ASSEMBLED LABEL NMUM OPERANDS COMENT
########################################
This would be ok to implement in the program, the initial idea would be to skip the assembling phase and have the program try and find the destination of the branch in memory, from here the above sum (0000002E - 00000036 - 2 = F6) could be calculated and then the branch instruciton could be assembled properly (with the final_assembled[XX] now having the correct value inside it).
This creates a huge problem though when trying to implement it this way when the following conditions are met in the form below:
Code:
########################################
4 00000014 323900009999 WISH: MOVE $9999,D1
5 0000001A 3401 MOVE D1,D2
6 0000001C 323C0000 MOVE #0000,D1
7 00000020 60000016 BRA NICE
8 00000024 3238FFFF MOVE $FFFFFFFF,D1
9 00000028 60EA BRA WISH
10 0000002A 32387999 MOVE $7999,D1
11 0000002E 32387999 TEST: MOVE $7999,D1
12 00000032 32387999 MOVE $7999,D1
13 00000036 60F6 BRA TEST
14 00000038 323C0000 NICE: MOVE #0000,D1
########################################
line MEMORY ASSEMBLED LABEL NMUM OPERANDS
########################################
As you can see, the BRA on line 7 takes up more space in memory than the BRA in line 13.
The above illustrates a classic catch 22 situation where none of the BRA instructions can be correctly assembled due to other branch instructions being the way of the other. (Basically I cant determin how much memory each would take up due to my not being able to figure out the size of each branching instruction).
This is my main problem, and right now im completely stuck because of it.
HELP!!!!!!!!!!
From Garry
Re: 68000 assembler (building one that is)
Quote:
Originally posted by Nutcasey
Code:
########################################
4 00000014 323900009999 WISH: MOVE $9999,D1
5 0000001A 3401 MOVE D1,D2
6 0000001C 323C0000 MOVE #0000,D1
7 00000020 60000016 BRA NICE
8 00000024 3238FFFF MOVE $FFFFFFFF,D1
9 00000028 60EA BRA WISH
10 0000002A 32387999 MOVE $7999,D1
11 0000002E 32387999 TEST: MOVE $7999,D1
12 00000032 32387999 MOVE $7999,D1
13 00000036 60F6 BRA TEST
14 00000038 323C0000 NICE: MOVE #0000,D1
########################################
line MEMORY ASSEMBLED LABEL NMUM OPERANDS
########################################
As you can see, the BRA on line 7 takes up more space in memory than the BRA in line 13.
The above illustrates a classic catch 22 situation where none of the BRA instructions can be correctly assembled due to other branch instructions being the way of the other. (Basically I cant determin how much memory each would take up due to my not being able to figure out the size of each branching instruction).
This is my main problem, and right now im completely stuck because of it.
I don't remember 68000 well, but in the other assemblers I used there were two forms, branch and long branch. The branch would be limited to 256 bytes forward & back, and the long would take care of the rest.
The way you have it implemented, how do you tell the address size for any branch?
In your example, how do you know the
BRA NICE is a 3 byte destination and
BRA TEST is a 1 byte destination? What is it that distinguishes this branch between 60F6, 60F632 and 60F6323C?