1. Explain what happens (play computer carefully, this is tricky) and why when t
ID: 3840489 • Letter: 1
Question
1. Explain what happens (play computer carefully, this is tricky) and why when the following program is executed?
ldc y
swap
call x
x: halt
y: dw -1
2. Describe the two phases of the assembler execution and what happens during these two phases.
3. If a label of a dw declaration is used in an immediate instruction what is loaded into the argument field of the instruction.
4. Can H1 "jump" instructions be used to easily implement a subroutine call/return technique? If not why not?
5. What is the special function of the "call" instruction that allows a subroutine to return to it's caller at the next instruction after the "call"?
Explanation / Answer
Answer
1.
When the given program is executed, below is what happens:
ldc y ; transfer data from memory to coprocessor y
swap ; exchanges the low order and high order nibbles ; within the accumulator
call x ; calls the subroutine or function indicated by x
x: halt ; subroutine x, which halts the program
y: dw -1 ; coprocessor y, defining word for data -1
2.
The two phases of the assembler exection are:
a. data manupulation
b. result storing
Data manupulation includes the below steps:
i. instruction fetch
ii. decode instruction and fetch operands
iii. perform ALU operation
Result storing has the below steps:
i. Access memory
ii. write back result to register file
iii. Updtae the PC
3.
If a label of a dw declaration is used in an immediate instruction space(depending on the machine type, for example 2 bytes on x86 32 bit system) is loaded into the argument field of the instruction.
4.
H1 "jump" instructions cannot be used to easily implement a subroutine call/return technique because jump instruction won't save the location to which the flow has to return when the subroutine is complete.
5.
In assemble program, the call instruction first pushes the current code location onto the hardware supported stack in memory, and then do an unconditional jump to the code location indicated by the operand label. Unlike the jump instructions, the call instruction saves the location to return when the subroutine is completed.
The ret instruction implements a subroutine return mechanism. This instruction first pops a code location off the hardware supported in-memory stack. It then performs an unconditional jump to the retrieved code location.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.