Week 2 Lab

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CS211 Lab 1

Objectives

After completing this lab, students should be able to


 Use CPUSim software for machine and assembly language programming
 Understand Wombat 1 computer
 Write and execute machine language codes for Wombat 1 computer
 Debug machine language codes for errors

Introduction

Machine language programming was the first generation programming language. This
programming language codes are only in zeros and ones. Due to the drawbacks of first
generation language such as time consuming, lengthy programs etc, resulted in
Assembly language programming. This programming language used symbolic names
instead of zeros and ones as in machine language one. The drawbacks of machine
language became the advantages of assembly language programming.

CPUsim is a software which simulates CPU of a computer to understand register set,


memory, microinstruction set, machine and assembly language programming. This
computer is known as Wombat 1 computer. The following figure illustrates Wombat 1
computer.

Figure 1: Wombat 1 machine with data movement


(Source: www.cs.colby.edu/~djskrien/CPUSim/ )

Page 1 of 6
There are six registers in Wombat 1 machine:
 acc – refers to accumulator. All computation are done in accumulator. Reading a
value from file or console will be stored in accumulator. To write to the file or
console, a value must be loaded to the accumulator.
 pc – program counter. It contains address main memory location that contains
the next instruction to be executed.
 mar – memory address register. This is for transferring data to memory.
 mdr – memory data register. This is for transferring data to and from memory.
 ir – instruction register. The instruction is decoded in this register. Instructions
consist of opcode and operand but this two are combined as one instruction. In
order to separate opcode and operand, an instruction must be decoded.
 status – status register. This is used for halting the machine. It consists of halt-bit
which can be set to zero or one.

The following figure shows the size of the registers.

Figure 2: Size of the registers

In addition to the registers, the machine also consists of the main memory. This is where
the instructions are stored. Figure 3 illustrates the main memory.

Page 2 of 6
Figure 3: Main memory

This lab will focus on only machine language programming. The Wombat 1 machine has
12 instructions which is shown in the following figure:

Figure 4: Machine instructions

These machine instructions will be used to do machine and assembly language


programming. These machine instructions operate on microinstruction shown below.

Page 3 of 6
This is the
implementation
of machine
instruction
Existing “load”
machine
instruction

Existing
micro
instruction

Figure 5: Implementation of machine instruction

There are 7 transfer, 4 arithmetic, 2 test, 1 increment, 1 decode, 2 input/output, 2


memory access, and 1 set condition-bit microinstructions. The machine operates on
Fetch Sequence. For now, fetch sequence is the order on which instructions are fetched,
decoded and executed. The following figure shows the fetch sequence.

Page 4 of 6
Figure 6: Fetch Sequence

The following is the machine language program.

Instruction
Comments after
semi colon
Figure 7: Machine language program

Page 5 of 6
An instruction is 16 bit long on wombat machine. Out of those 16 bits, first 4 bits is the
opcode and the 12 bits is operand. For example, the first instruction is
0011000000000000. The opcode is 0011 and operand is 000000000000. 0011
represents 3 which is the “read” machine instruction. Likewise every instruction will
have opcode and operand.

Tasks to perform:
1. Load the machine instruction in the file named “sample”. Go to File menu, click
on LOAD RAM.
2. Select the file “Sample”. The machine codes will be loaded in RAM. Check the
RAM for this.
3. Go to Execute menu, select “Run”. Enter values from the console.

Page 6 of 6

You might also like