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

Can please someone help me to do the written description for this 68k program??

ID: 2080083 • Letter: C

Question

Can please someone help me to do the written description for this 68k program??

ORG $400 QUEST1 B ENTER M DC.B MQUEST1 EQU 9 QUEST DC.B ENTER N MQUEST2 EQU 9 ANSWR. DC.B Y (M,N) SWR EQU 9 MANS TERMMSG DC.B THE END MTERMMSG EQU 7 LF EQU $0A. CR EQU $0D ORG $1000 LOOP MOVE. L #1,DO SET TRAP FOR QUEST1 MOVEA. L #QUEST 1,A1 MOVE. L #MQUEST1, D1 TRAP #15 MOVE. L #4, DO READ FROM CONSOLE TRAP #15 MOVE. L D1,D4 CMP L #0,D4 BEQ LAST IF M IS ZERO RUN TERMPROG MOVE.L #1, DO SET TRAP FOR QUEST2 MOVEA.L #QUEST2,A1 MOVE. L #MQUEST2, D1 TRAP #15 MOVE. L #4, DO READ FROM CONSOLE TRAP #15 MOVE. L D1,D5 BSR CALC BRANCH TO CALCULATE AND STORE ANSWER MOVE.L #1, DO SET TRAP TO DISPLAY ANSWER STRING MOVEA. L HANSWR, A1 MOVE. L #MANSWR, D1 TRAP #15 MOVE .L #3, DO MOVEA.L D1 A1 MOVE .L D5, D1 TRAP #15

Explanation / Answer

=>ORG $400

tells the assembler to start loading instructions at address 40016 which is 102410. The reason for this is the 68k uses the first 1024 bytes of memory, 0 – 3FF16 for a special purpose.

=> QUEST1 DC.B 'ENTER M: '

Here QUEST1 is Memory location , compiler directives is DC, which stands for define constant. This directive allows us to load a constant into memory before execution. The DC command can be followed by one of the following qualifiers : .L, .W , or .B .

In our case we are referring to memory location QUEST1 and defining constant to load to QUEST1 we are asking to enter M (bytes)

=> MQUEST1 EQU 9

here 9 is equal to label MQUEST1.

When a label is encountered in the source code, it is defined to have a value equal to the current location counter. This symbol may be used elsewhere is the program to refer to that location.

=> QUEST2 DC.B 'ENTER N: '

Here QUEST2 is Memory location , compiler directives is DC, which stands for define constant. This directive allows us to load a constant into memory before execution. The DC command can be followed by one of the following qualifiers : .L, .W , or .B . (.B means Constant Block)

In our case we are referring to memory location QUEST2 and defining constant to load to QUEST2 we are asking to enter N (bytes)

=> MQUEST2 EQU 9

here 9 is equal to label MQUEST2

When a label is encountered in the source code, it is defined to have a value equal to the current location counter. This symbol may be used elsewhere is the program to refer to that location.

=> ANSWR DC.B 'Y(M,N) = '

Here ANSWR is Memory location ,compiler directives is DC, which stands for define constant. This directive allows us to load a constant into memory before execution. The DC command can be followed by one of the following qualifiers : .L, .W , or .B(Constant Block) .

In our case we are referring to memory location ANSWR and After doint operation Y(M,N) the result of constant Block will be load to address ANSWR.

=> MANSWR EQU 9

The 9 is equal to MANSWR label.

When a label is encountered in the source code, it is defined to have a value equal to the current location counter. This symbol may be used elsewhere is the program to refer to that location.

=> TERMMSG DC.B 'THE END'

The Block "THE END" defined in the memory of "TERMMSG"

=> MTERMMSG EQU 7

The 7 is equal to MTERMMSG label.

When a label is encountered in the source code, it is defined to have a value equal to the current location counter. This symbol may be used elsewhere is the program to refer to that location.

=> LF EQU $0A

0A address assigned to LF label . (L=0000, F = 1010)

=> CR EQU $0D

0D address assigned to CR label ( C = 0000, R = 1101)

=> ORG $1000

tells the assembler to start loading instructions at address 100016

=>MOVE.L #1, D0

After loop starts initially here 1 is moving to D0 register. By MOVE.L instruction the assembler produces a listing file which shows the source code alongside the the object code produced by the assembler including address , instruction word , number of line of code and source code. Thats why it is called listing file after executing this instruction.

=> MOVE.L #QUEST1, A1

Copying data from address QUEST1 to A1 register. Both have same information after this.(.L means it will result in listing file as said above)

=> MOVE.L #MQUEST1, D1

Copying data from address MQUEST1 to D1 register. Both have same information after this.(listing file)

=> TRAP #15

This instruction forces the processor to initiate exception processing. The vector number used by the TRAP instruction is in the range 0 to 15 and, therefore, supports 16 traps. The TRAP instruction is used to perform operating system calls and is system independent. That is, the effect of the call depends on the particular operating environment.

Here we using TRAP #15 for performing I/O. (calling OS)

=> MOVE.L #4, D0

TRAP #15

The above 2 lines says that We are copying 4 to D0 register which is reading from console and calling OS by TRAP #15

=> MOVE.L D1, D4

CMP.L #0, D4

BEQ LAST

in these lines we are copying content of D1(MQUEST1 data which is M what we copied previously) to D4 register , after this instruction both registers had same information. Then CMP.L #0, D4 will do the comparison for 0 and D4 register. BEQ LAST will check whether branch on equal to zero or not , if equal then it will jump to LAST block of code

LAST: MOVE.L #1, D0

MOVEA.L #TERMMSG,A1

MOVE.L #MTERMMSG , D1

TRAP #15

END $1000

This LAST block of code will first copy 1 to D0 register . MOVEA.L instruction will move content from TERMMSG to destination A1 register which is previously assigned Block to TERMMSG as "THE END". Next The content from MTERMMSG will copy into D1 register which is 7 . Next WE are calling OS by TRAP #15. Next we are ending source file with address $1000. Compiler wont see the sourcefile instructions after END instruction.

If before LAST , if BEQ is not zero then it will continue

Next we are setting TRAP for QUEST2

=> MOVE.L #1, D0

MOVE.L #QUEST2, A1

MOVE.L #MQUEST2, D1

TRAP #15

MOVE.L #4, D0

TRAP #15

MOVE.L D1,D5

BSR CALC

In this we are setting trap for QUEST 2. here 1 is moving to D0 register. By MOVE.L instruction the assembler produces a listing file which shows the source code alongside the the object code. MOVE.L #QUEST2, A1 will copy QUEST2 content(which is N) to A1 register , MOVE.L #MQUEST2, D1 will copy contents of MQUEST2 (which is 9) to D1 register. Next we calling OS. next we are moving 4 to D0 register and again calling OS by TRAP. NExt we are moving D1 content to D5 register which is copied from MQUEST2 previously. BSR CALC will be is used to call a procedure or a subroutine named CALC. Since it provides relative addressing.

CALC: MULU D4, D5

ADD.L #7, D5

RTS

We have QUEST1 result M is in D4 register and QUEST2 result N is in D5 register. MULU instruction will multiply the lower order bits of D5 content with D4 content and store the whole result in D5 register. next we are adding 7 to the D5 register content by ADD.L instruction. Then by RTS instruction the program counter is pulled from the stack and the previous value of the PC is lost. RTS is used to terminate a subroutine CALC.

After this the program will again do the instructions after BSR.

it will move 1 to D0 register again. By MOVE.L #ANSWR A1 will copy content ASNWR(Y(M,N)) to A1 register. By MOVE.L #MANSWR D1 will copy content MASNWR to D1 register. Then we are calling OS by TRAP instruction. next we are moving 3 to D0 register by MOVE.L #3 D0. Next we are copying D1 register content which is MASNWR to A1 register by by MOVE.L D1 A1 . Next we are copying D5 register content( which is result of multplication of lower order bits of D5 and D4 ) to D1 register by by MOVE.L D5 D1 . Next we are calling OS.

next we are moving LF content to D1 register by immediate addresing mode by MOVE.L #LF D1. and copying 6 to D0 calling OS. Next we are moving CR content to D1 and copying 6 to D0 and calling OS .

A BRA is an unconditional relative jump (or goto). You use a BRA instruction to write position independent code, because the destination address (branch target address) is specified with respect to the current value of the PC. A JMP instruction does not produce position independent code. by BRA LOOP we are repeating loop.