Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

generate the corresponding machine code (generate all adresses) of the following

ID: 3666281 • Letter: G

Question

generate the corresponding machine code (generate all adresses) of the following Sim68 assembly program. Describe what each segment does also.

org      $1000

sub       d1,d1         

movea     d1,a0    

move      n(a0),d2

move      x(a0),d0   

loop                   move      neg_one(a0), d1

add       d1,d0

cmp       d2,d0

blt       loop

muls      d0,d0        

move      d0,y(a0)

                          swap      d0

                          move      d0,y+2(a0)

move      exitcode(a1),d0

trap      #0

n                        dc        10

x                        dc        15

neg_one           dc        -1

     y                 ds        2

exitcode           dc        3

end

some extra codes :

org   $1000 = $001000  

x   dc    30 = 30 ($001E).

trap   #0 = $4E40 =%0100111001000000

Explanation / Answer

Answer

org $1000

Means that the actual Program starts at memory location $001000(24 bit)

sub d1,d1

movea d1,a0

move n(a0),d2

move x(a0),d0, meaning move memory data located at address (a0+n) to data reg. d2. n is the memory address displacement that can be a variable defined as a constant (dc) or a storage (ds). To get the value of x, one has to compute its actual address in the program which starts at org.

move x(a0),d0            

move x(a0),d0, meaning move memory data located at address (a0+x) to data reg. d0. x is the memory address displacement that can be a variable defined as a constant (dc) or a storage (ds). To get the value of x, one has to compute its actual address in the program which starts at org.

loop:

move neg_one(a0), d1

move neg_one(a0),d1, meaning move memory data located at address (a0+neg_one) to data reg. d1. neg_one is the memory address displacement that can be a variable defined as a constant (dc) or a storage (ds). To get the value of neg_one, one has to compute its actual address in the program which starts at org.

add d1,d0

add the d1 ,d0 values

cmp d2,d0

comparision between d2, d0

It also had an instruction to quickly push or pop a series of registers, which made function prologues and epilogues very compact:

blt loop

muls d0,d0

move d0,y(a0)

swap d0

move d0,y+2(a0)

move exitcode(a1),d0

trap #0

trap   #0, meaning stop program. The code is: $4E40 =%0100111001000000

n dc 10

x dc 15  

x   dc    15, meaning at memory address location x, we define a 16 bit constant 30 ($001E).

neg_one dc 1

y ds 2

y   ds    2, meaning starting at memory address location z, we define a 16 bit variable (NO value is stored & next PC = PC+4).

exitcode dc 3

end

end of the algorithm