Example 1
Given the following Sim68 program, generate the corresponding machine code showing the memory address of each line.
Note: you should hand assemble and NOT use an assembler to generate the code for you!!
org $4000
sub d0,d0
move d0,a1
move base(a1),d1
move height(a1),d2
cmp d0,d1
blt neg
cmp d0,d2
blt neg
mul d1,d2
move two(a1),d3
div d3,d2
move d2,result(a1)
bra done
neg move err(a1),result(a1)
done move exitcode(a0),d0
trap #0
base ds 1
height ds 1
result ds 1
two ds 1
err dc $FFFF
exitcode dc 3
address |
Machine code |
hex |
instruction |
|
|
|
org $4000 |
$004000 |
1001 0000 0100 0000 |
9040 |
sub d0,d0 |
$004002 |
0011 0010 0100 0000 |
3240 |
move d0,a1 |
$004004 |
0011 0010 0010 1001 |
3229 |
move base(a1),d1 |
$004006 |
$402E |
402E |
|
$004008 |
0011 0100 0010 1001 |
3429 |
move height(a1),d2 |
$00400A |
$4030 |
4030 |
|
$00400C |
1011 0010 0100 0000 |
B240 |
cmp d0,d1 |
$00400E |
0110 1101 0001 0010 |
6D12 |
blt neg |
$004010 |
1011 0100 0100 0000 |
B440 |
cmp d0,d2 |
$004012 |
0110 1101 0000 1110 |
6D0E |
blt neg |
$004014 |
1100 0101 1100 0001 |
C5C1 |
mul d1,d2 |
$004016 |
0011 0110 0010 1001 |
3629 |
Move two(a1),d3 |
$004018 |
$4034 |
4034 |
|
$00401A |
1000 0101 1100 0011 |
85C3 |
div d3,d2 |
$00401C |
0011 0011 0100 0010 |
3342 |
move d2,result(a1) |
$00401E |
$4032 |
4032 |
|
$004020 |
0110 0000 0000 0110 |
6006 |
bra done |
$004022 |
0011 0011 0110 1001 |
3369 |
move err(a1),result(a1) |
$004024 |
$4036 |
4036 |
|
$004026 |
$4032 |
4032 |
|
$004028 |
0011 0000 0010 1000 |
3028 |
move exitcode(a0),d0 |
$00402A |
$4038 |
4038 |
|
$00402C |
0100 1110 0100 0000 |
4E40 |
trap #0 |
$00402E |
|
|
base ds 1 |
$004030 |
|
|
height ds 1 |
$004032 |
|
|
result ds 1 |
$004034 |
0000 0000 0000 0010 |
0002 |
two dc 2 |
$004036 |
1111 1111 1111 1111 |
FFFF |
err dc $FFFF |
$004038 |
0000 0000 0000 0011 |
0003 |
exitcode dc 3 |
neg = PC + 2 + displacement
$4022 = $400E + 2 + displacement
displacement = $4022 - $4010 = 12
neg = PC + 2 + displacement
$4022 = $4012 + 2 + displacement
displacement = $4022 - $4014 = 0E
done = PC + 2 + displacement
$4028 = $4020 + 2 + displacement
displacement = $4028 - $4022 = 6
Generate the object code module (in hexadecimal) for the program.
904032403229402E
34294030B2406D12
B4406D0EC5C13629
403485C333424032
6006336940364032
302840384E40xxxx
xxxxxxxx0002FFFF
0003
Example 2.
Convert following machine code in hexadecimal into Sim68 assembly code.
Address |
Machine code (binary) |
Hex |
instruction |
|
|
|
org $3000 |
$3000 |
1001000001000000 |
9040 |
sub d0,d0 |
$3002 |
0011000001000000 |
3040 |
move d0,a0 |
$3004 |
0011001000101000 |
3228 |
move x(a0),d1 |
$3006 |
X |
302C |
|
$3008 |
0011010000101000 |
3428 |
move y(a0),d2 |
$300A |
Y |
302E |
|
$300C |
0011011000000001 |
3601 |
move d1,d3 |
$300E |
1101011001000010 |
D642 |
add d2,d3 |
$3010 |
0011000000000011 |
3003 |
move d3,d0 |
$3012 |
1100011111000000 |
C7C0 |
mul d0,d3 |
$3014 |
1001001001000010 |
9242 |
sub d2,d1 |
$3016 |
0110011100001000 |
6708 |
beg target1 |
$3018 |
1000011111000001 |
87C1 |
div d1,d3 |
$301A |
0011000101000011 |
3143 |
move d3,res(a0) |
$301C |
Result |
3030 |
|
$301E |
0110000000000110 |
6006 |
bra target2 |
$3020 |
0011000101101000 |
3168 |
move err(a0),res(a0) |
$3022 |
Err |
3032 |
|
$3024 |
Res |
3030 |
|
$3026 |
0011000000101000 |
3028 |
move exitcode(a0),d0 |
$3028 |
Exitcode |
3034 |
|
$302A |
0100111001000000 |
4E40 |
trap #0 |
$302C |
X |
ds |
x ds 1 |
$302E |
Y |
ds |
y ds 1 |
$3030 |
res |
ds |
res ds 1 |
$3032 |
err |
FFFF |
err dc -1 |
$3034 |
exitcode |
0003 |
exitcode dc 3 |
Target1 = pc + 2 + displacement
displacement: = $08
pc= $3016
Target1 = 3020
Target2 = $301E + 2 + 06
= $3026