Computer Architecture Chapter 6
-
Upload
maryam-nehme -
Category
Documents
-
view
220 -
download
0
Transcript of Computer Architecture Chapter 6
-
8/2/2019 Computer Architecture Chapter 6
1/16
Computer System ArchitectureCCEE 313
Dr. Abir A. EL ABED
Chapter 6Programming the Basic Computer
-
8/2/2019 Computer Architecture Chapter 6
2/16
-
8/2/2019 Computer Architecture Chapter 6
3/16
25 Instruction Set of the basic
computer
Memory Reference Instruction
Has 3 parts: a mode bit, an operation
code of 3 bits, and a 12-bit address
Register Reference Instruction
16-bit operation code
First digit of a register reference
instruction is always 7
Input-output Instruction
First digit is always F
6-1 Introduction
3
-
8/2/2019 Computer Architecture Chapter 6
4/16
6-2 Machine Language
Program = list of statements for directing the computer to perform a task
Various types of programming languages may be write for computer
Computer can execute only the binary form of statements => Programs written in other
language must be translated to binary
Program Categories
1) Binary Code (Tab. 6-2)
A sequence of instructions and operand in binary that list the exact representation ofinstructions as they appear in computer memory
2) Octal or Hexadecimal Code (Tab. 6-3)
Equivalent translation of the binary code to octal or hexadecimal representation
3) Symbolic Code (Tab. 6-4)
User employs symbols (letters, numerals, or special characters) for operation, address
and other parts of instruction code
Each symbols can be translated into binary coded instruction
Translation done by an assembler
4) High Level Language (Tab. 6-6)
C, Fortran,
4
-
8/2/2019 Computer Architecture Chapter 6
5/16
6-3 Assembly Language Programming language defined by a set of rules
The rules for writing assembly language program
Documented and published in manuals (from the computer manufacturer)
Rules of the Assembly Language
Each line of an assembly language program is arranged in three columns called fields
Fields specify the following information:
1. Label field : empty or symbolic address
2. Instruction field : specifies a machine instruction or a pseudoinstruction
3. Comment field : empty or comment
Symbolic Address (Label field)
One, two, or three, but not more than three alphanumeric characters The first
character must be a letter; the next two may be letters or numerals
A symbolic address is terminated by a comma (recognized as a label by the
assembler), (ex. Table 6-5)
5
-
8/2/2019 Computer Architecture Chapter 6
6/16
Instruction Field
1. A memory-reference instruction(MRI)
Ex) ADD OPR
2. A register-reference or input-output instruction(non-MRI)
CLA (register-reference), INP (input-output)
3. A pseudoinstruction with(ORG N) or without(END) an operand
Comment field
Comment filed must be preceded by a slash(recognized by assembler as
comment)
Translation to Binary
Assembler = the translation of the symbolic(= assembly) program into binary
Address Symbol Table = Hexadecimal address of symbolic address
MIN = 106, SUB = 107, DIF = 108
6-3 Assembly Language
6
-
8/2/2019 Computer Architecture Chapter 6
7/16
6-4 The Assembler
Assembler = a program that accepts a symbolic language program and
produces its binary machine language equivalent
Input symbolic program is called source program
Resulting binary program is called object program
7
-
8/2/2019 Computer Architecture Chapter 6
8/16
6-4 The Assembler
Representation of Symbolic Program in Memory : Tab. 6-11
To starting the assembly process, symbolic program must be stored inmemory
A program consists of symbols => its representation in memory use analphanumeric character code
In basic computer, each character is represented by 8-bit code
Each character is assigned two hexadecimal digits which can be convertedto 8-bit code
Line of Code : PL3, LDA SUB I (Carriage return CR)
The assembler recognizes a CR code as the end of a line of code
Code for CR is produced when the return key is depressed
The following line PL3, LDA SUB I is stored in 7 consecutive memorylocations (Tab 6-11)
8
-
8/2/2019 Computer Architecture Chapter 6
9/16
o An input program is scanned by the assembler twice to produce the equivalentbinary program
o Two Pass Assembler
1) 1st pass : Generate user defined address symbol table with their binaryequivalent symbol
- Binary translation is done during the 2nd pass
- To track the location of instructions, the
assembler uses location counter (LC)
- LC stores the value of the memory locationassigned to the instruction or operand
presently being processed
- ORG pseudoinstruction initializes LC to the
value of first location
- LC is incremented by 1 after processing each
line of code
9
-
8/2/2019 Computer Architecture Chapter 6
10/16
2) 2nd pass : Binary translation
10
MRI: Memory Reference Instruction
-
8/2/2019 Computer Architecture Chapter 6
11/16
6-7 Subroutines A set of common instruction that can be used in a programmany times
Each time that a subroutine is used in the main part of the program, a branch
is executed to the beginning of the subroutine
After the subroutine has been executed, a branch is made back to the main
program
A branch can be made to the subroutine from any part of the main program
Problem: how the subroutine knows which location to return to?
All computer provide special instructions to facilitate subroutine entry and
return
In basic computer, the link between the main program and a subroutine is
the BSA instruction (Branch and Save return Address)
11
-
8/2/2019 Computer Architecture Chapter 6
12/16
12
Program: shifting a word 4 times
- Load the value of X into the
accumulator AC
- BSA instruction at location 101
- Subroutine SH4 must return to
location 102 after finishes its
task
- When BSA executed, controlunit stores the return address
102 into the location defined
by the symbolic address SH4
(which is 109)
- And value of SH4 + 1 is
transferred into the programcounter
- After execution of instruction SH4, HEX 0 the memory location 109 contains the binary
equivalent of 102
-
8/2/2019 Computer Architecture Chapter 6
13/16
Computation in the subroutine circulatesthe content of AC four times to the left
To accomplish a logical shift operation,the four low-order bits must be set tozero => this is done by masking FFF0 withthe content of AC
BUN SH4 I returns the computer to themain program (to the address stored in
location SH4 == location 102)
STA X store the result in the accumulatorAC into X
13
- The first memory location of each subroutine serves as a link between the main programand the subroutine
- The procedure for branching to a subroutine and returning to the main program is
referred to as a subroutine linkage
-
8/2/2019 Computer Architecture Chapter 6
14/16
6-8 Input-Output Programming
- Users write programs with symbols defined by programming language
- Symbols are strings of characters and each character is assigned an 8-
bit code
- A binary-coded character enters the computer when an INP (input)
instruction is executed
- A binary-coded character is transferred to the output device when an
OUT (output) instruction is executed
- Output device detects the binary code and types the corresponding
character
14
-
8/2/2019 Computer Architecture Chapter 6
15/16
- SKI instructions the input flag to see if a character is available for transfer
- INP transfers the binary-coded character into AC(0-7)- OUT instruction print out the character to the terminal
15
-
8/2/2019 Computer Architecture Chapter 6
16/16
Interrupt Program
16