Está en la página 1de 16

Computer System Architecture

CCEE 313

Dr. Abir A. EL ABED


Chapter 6

Programming the Basic Computer

6-1 Introduction
A computer system includes: Hardware: physical components and all associated equipment Software: programs that are written for the computer

A program = A sequence of machine instructions


Machine instructions inside the computer form a binary pattern (difficult to understand for people) => Preferable to write programs with familiar symbols (i.e. alphanumeric character set) Translate user-oriented symbolic program into binary programs recognized by the hardware Goals of this chapter Introduce some elementary programming concepts and their relation to hardware representation of instructions The basic operation and structure of a program that translates a users symbolic program into binary equivalent program
2

6-1 Introduction
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
3

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 of instructions as they appear in computer memory Equivalent translation of the binary code to octal or hexadecimal representation 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

2) Octal or Hexadecimal Code (Tab. 6-3)


3) Symbolic Code (Tab. 6-4)

4) High Level Language (Tab. 6-6)


C, Fortran,
4

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

6-3 Assembly Language


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

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

6-4 The Assembler


Representation of Symbolic Program in Memory : Tab. 6-11
To starting the assembly process, symbolic program must be stored in memory A program consists of symbols => its representation in memory use an alphanumeric character code In basic computer, each character is represented by 8-bit code Each character is assigned two hexadecimal digits which can be converted to 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 memory locations (Tab 6-11)

o An input program is scanned by the assembler twice to produce the equivalent binary program o Two Pass Assembler 1) 1st pass : Generate user defined address symbol table with their binary equivalent 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 location assigned 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

2)

2nd pass : Binary translation

MRI: Memory Reference Instruction

10

6-7 Subroutines
A set of common instruction that can be used in a program many 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

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, control unit 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 program counter

- After execution of instruction SH4, HEX 0 the memory location 109 contains the binary equivalent of 102
12

Computation in the subroutine circulates the content of AC four times to the left To accomplish a logical shift operation, the four low-order bits must be set to zero => this is done by masking FFF0 with the content of AC BUN SH4 I returns the computer to the main program (to the address stored in location SH4 == location 102) STA X store the result in the accumulator AC into X

- The first memory location of each subroutine serves as a link between the main program and the subroutine - The procedure for branching to a subroutine and returning to the main program is referred to as a subroutine linkage
13

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 8bit 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

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

Interrupt Program

16

También podría gustarte