0% found this document useful (1 vote)
500 views

Advanced CPU Instructions: Laboratory Exercise #5

The document describes a laboratory exercise on advanced CPU instructions. The objectives are to use instructions like MOV, COMPARE, JUMP, addressing modes, subroutines, and passing parameters. Procedures are provided to work with flags, loops, memory access, subroutines, and passing parameters to a subroutine. Key concepts covered are CPU instruction categories, conditional jumps for loops, direct vs indirect addressing, calling and returning from subroutines, and passing parameters on the stack.

Uploaded by

Aubrey Tolentino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
500 views

Advanced CPU Instructions: Laboratory Exercise #5

The document describes a laboratory exercise on advanced CPU instructions. The objectives are to use instructions like MOV, COMPARE, JUMP, addressing modes, subroutines, and passing parameters. Procedures are provided to work with flags, loops, memory access, subroutines, and passing parameters to a subroutine. Key concepts covered are CPU instruction categories, conditional jumps for loops, direct vs indirect addressing, calling and returning from subroutines, and passing parameters on the stack.

Uploaded by

Aubrey Tolentino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: TOLENTINO, AUBREY C.

Score: _____

Program/Section: BSCpE – 5 Date: November 29, 2019

Laboratory Exercise #5
Advanced CPU Instructions
Objectives:

At the end of the exercise, the students should be able to:

 enter CPU instructions and describe the effects of COMPARE instruction on CPU status flags Z and
N,
 use the MOV instruction in doing programs
 construct a loop and explain JUMP instructions’ use on Z and N flags,
 use direct and indirect addressing to access memory location(s),
 construct a subroutine and call it, and
 pass parameter(s) to the subroutine

Materials:

 CPU-OS Simulator

Basic Principles:

The CPU instruction sets are often grouped together into categories that contains instructions with related
functions. The most encountered instruction is the MOV instruction which involves data movements.
Another instruction is the comparison instruction, e.g. CMP which involves setting or resetting of the status
flags Z and N.

The most useful feature of programming languages are the Loops or Iterative statement which involves
repetition of execution of codes until or while a condition is met. At the instruction level, it uses conditional
jump instructions to jump back to the start of the loop or to jump out of the loop.

Although instructions moving data to or from registers are the fastest instructions, it is still necessary to move
data in or out of the main memory (RAM). This method uses the direct addressing method in which memory
address is directly specified in the instruction itself.

But there are some instances or circumstances in which direct addressing is unsuitable and inflexible method
to use. In that case, an indirect addressing is use in which, the address of the memory location is not directly
included in the instruction but is stored in a register.

Another very useful feature of programming languages is subroutines which involves execution of sequences
of instructions many times. If however, it was not available, the same sequence of instructions would have
been repeated many times which increases the code size.
At the instruction level, a subroutine is called by an instruction known as CAL. This effectively jumps an
instruction but also saves an address of the next instruction. This is later used by a subroutine return
instruction, e.g. RET to return to the previous sequence of instructions.

Useful as they are, the subroutines are not very flexible without the use of the subroutine parameters.
Subroutine parameters are values that are passed to a subroutine to be consumed inside it. The common
method of passing it to the subroutines is through a program stack. The parameters are pushed on the stack
before the call instruction. These are then popped off the stack inside the subroutine and consumed.

Procedures:

1. Enter the following codes below and run it using a CPU-OS Simulator. Note the states of the status
flags Z and N after each compare instruction is executed and explain your observations.

MOV #1, R01


MOV #2, R02
ADD R01, R02

CMP #3, R02 Z flag


CMP #1, R02
CMP #4, R02 N flag

2. Add the following code below and run it. Summarize what the code is doing in plain English:

MOV #0, R01


Label1
ADD #1, R01
CMP #3, R01
JLT $Label1

To create a label, insert an instruction using the miscellaneous tab, use the NOP, write label 1 and
click the ENTER LABEL button.

- The instruction continues to increment until it reaches the value of 3.

3. Modify the above code by incrementing R01 to 1. By doing such, the last value of R01 becomes 4.

4. Add the following code and run. Click “SHOW PROGRAM DATA MEMORY…” button to see result
and make a note of what you see in the data.

STB #h41, 16
LDB 16, R03
ADD #1, R03
STB R03, 17

What is the significance of h in h41 above? Modify the above code to store the next two characters in
the alphabet. Write down the modified code below:

- Adding an h makes the h41 a hexadecimal value.


5. Add the following code and run. Click “SHOW PROGRAM DATA MEMORY…” button to see result
and make a note of what you see in the data.

Label2
MOV #16, R03
MOV #h41, R04
Label3
STB R04, @R03
ADD #1, R03
ADD #1, R04
CMP #h4F, R04
JNE $Label3

Explain the significance of @ in @R03 above:

- The @ above used in RO3 is for indirect addressing.

6. Convert program code in Number 5 into a subroutine by means of adding the following code before
Label2 and by inserting a RET as the last instruction in the subroutine.

MSF
CAL $Label2

Make a note of the contents of the PROGRAM STACK after an instruction MSF and an instruction
CAL are executed. What is the significance of the additional information?
.

7. Let’s make the above subroutine a little more flexible. Suppose we wish to change the number of
characters stored when calling the subroutine. Modify the calling and subroutine code in (6) as below:

MSF
PSH #h60
CAL $Label2

Label2
MOV #16, R03
MOV #h41, R04
POP R05
Label3
STB R04, @R03
ADD #1, R03
ADD #1, R04
CMP R05, R04
JNE $Label3
RET
Add a second parameter to change the starting address of the data as a challenge.

MSF
PSH #h60
PSH #16
CAL $Label2
Label2
POP R03
MOV #h41, R04
POP R05
Label3
STB R04, @R03
ADD #1, R03
ADD #1, R04
CMP R05, R04
JNE $Label3
RET

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy