Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Computer Architecture O 06 Programming the Basic Computer

Uploaded by

ayke607
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Computer Architecture O 06 Programming the Basic Computer

Uploaded by

ayke607
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Chapter 6: Programming the Basic

Computer

Computer Architecture
and Organization
INTRODUCTION

 A total computer system includes both hardware and


software.
 Those concerned with computer architecture should have a
knowledge of both hardware and software because the two
branches influence each other.
 Writing a program for a computer consists of specifying a
sequence of machine instructions which is in binary codes.
 Machine instructions inside the computer form a binary
pattern which is difficult for people to work with and
understand.

2
INTRODUCTION…

 It is preferable to write a program with the more familiar


symbols of the alpha numerical character set.
 As a result, there is a need for translate user-oriented
symbolic program into binary programs recognized by the
hardware which is called assembler.
 The 25 Instruction Set of the basic computer repeated here,

▪ Memory Reference Instruction (MRI)

▪ Register Reference Instruction (RRI)

▪ Input-output Instruction (IOI)

3
Symbol Hex Code Description
Memory-reference AND 0xxx 8xxx And memory word to AC
instruction ADD 1xxx 9xxx Add memory word to AC
LDA 2xxx Axxx Load memory word to AC
STA 3xxx Bxxx Store content of AC in memor
BUN 4xxx Cxxx Branch unconditionally
BSA 5xxx Dxxx Branch and Save return addre
ISZ 6xxx Exxx Increment and skip if zero
CLA 7800 Clear AC
CLE 7400 Clear E
Register -reference CMA 7200 Complement AC
instruction CME 7100 Complement E
CIR 7080 Circulate right AC and E
CIL 7040 Circulate left AC and E
INC 7020 Increment AC
SPA 7010 Skip next instruction if AC pos
SNA 7008 Skip next instruction if AC neg
SZA 7004 Skip next instruction if AC zero
SZE 7002 Skip next instruction if E is 0
HLT 7001 Halt computer
Memory-reference INP F800 Input character to AC
instruction OUT F400 Output character from AC
SKI F200 Skip on input flag
SKO F100 Skip on output flag
ION F080 Interrupt On
IOF F040 Interrupt Off 4
MACHINE LANGUAGE

▪ Program is a list of instructions or statements for directing


the computer to perform a required data processing task
▪ There are various types of programming languages, but
the computer can execute only when they are
represented internally in binary codes.
▪ Programs written can be in one of the following
Categories:
1. Binary Code(Machine Language)
✓ The program is written in binary codes(machine language)

2. Octal or Hexadecimal Code


✓ This is equivalent translation of binary codes to octal or hexa.

5
MACHINE LANGUAGE…
3. Symbolic Code :( Assembly Language )
✓ The user employ symbols for operation part, the address part,
and other parts of the instruction
✓ Each symbolic instruction can be translated to binary coded
instruction
✓ This translation is done by a special program called assembler.
4. High Level Language
✓ The program is written in a sequence of statements in forms that
people prefer to think when solving a problem.
✓ These statements translated to binary code by compiler.
✓ Machine language is a program that is written in a binary format.

6
COMPARISON OF PROGRAMMING
LANGUAGES
▪ The program is to add two numbers (C = A + B )
▪ The first column is memory location and the second indicate the
content of each location.
▪ The program is stored in the indicated portion of memory as
shown in table. a. and, the execution is beginning from address 0.
▪ However, for people this program is difficult to understand what
the program is.
Table A: Binary Program to Add Two Numbers

7
COMPARISON OF PROGRAMMING
LANGUAGES…
▪ But, writing in binary is tedious.
▪ We reduce the number of digits if we write the hexadecimal
equivalent to binary code(shown in Table B)
▪ But, it must be converted to binary code to be executed by a
computer.
Table B: Hexadecimal Program to Add Two Numbers

8
COMPARISON OF PROGRAMMING
LANGUAGES…
▪ The program is written in symbolic instead of binary and
hexadecimal code(Symbolic programs is shown in Table C)
▪ The address part of MRI as well as, operands, remain in their
hexadecimal . Comments are to explain the function of each
instruction.
▪ Symbolic programs are easier to handle, and it is preferable to
write programs with symbols
▪ This symbols also has to converted to binary to be executed by a
computer. Table C: Program with Symbolic Operation Codes

9
COMPARISON OF PROGRAMMING
LANGUAGES…
▪ A program in Table D is the assembly-language program for
adding two numbers.
▪ The ORG is not a machine instruction and it is to specify an
origin, that is, the memory location of the next instr. below it.
▪ The next three lines have symbolic addresses and, their values
are specified by their being present as a label in the first column.
▪ Decimal operands are specified following the symbol DEC.
▪ The symbol END indicating that the end of the prog.
Table D: Assembly Language Program to Add Two Numbers

10
COMPARISON OF PROGRAMMING
LANGUAGES…
▪ The equivalent Fortran program is shown as below.

▪ The two values for A and B may be specified by an


input data statement.
▪ The operation is specified by one statement.

▪ The compiler translate this symbols of Fortran


program into the binary values

Table E: Fortran Program to Add Two Numbers

11
ASSEMBLY LANGUAGE
▪ A programming language is defined by a set of rules.

▪ The rules for writing assembly language programs are


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.

1. Label field : it may be empty or specify a symbolic address

2. Instruction field: specify a machine instruction or pseudo-


instruction
3. Comment field : may be empty or it may include a comment 12
ASSEMBLY LANGUAGE…
▪ Symbolic Address(Label field)
✓ Consist of one, two, or three, but not more than three alphanumeric
character
✓ The first character must be a letter; the next two may be letters or
numerals
✓ The symbols can be chosen arbitrarily by the programmer.

✓ A symbolic address in the label field is terminated by a comma


(recognized as a label by the assembler)
▪ Instruction Field in an assembly language program may specify one of the
following items:
✓ A memory-reference instruction(MRI)

✓ A register-reference or input-output instruction(non-MRI)

✓ A pseudo-instruction with operand(e.g. DEC N) or without an operand


(e.g. END). 13
ASSEMBLY LANGUAGE…
▪ A memory-reference instruction occupies 2 or 3 symbols
separated by spaces.
✓ The first must be a 3-letter symbol defining a MRI operation
code.
✓ The second is a symbolic address.

✓ The third symbol, which may or may not present, is I.

✓ If I is missing, the line denotes a direct address instruction

✓ The present of I denote that an instruction is indirect address


instruction.
✓ A non-MRI is defined as an instruction that does not have an
address part.
14
ASSEMBLY LANGUAGE…
▪ The following is an illustration of the symbols that may be placed in
the instruction field of a program.
✓ ADD A (direct address MRI),
✓ AND B I (indirect address MRI)
✓ CLA (register-reference),
✓ INP (input-output)
▪ The first three-letter symbol in each line must be one of the
instruction symbols of the basic computer.
▪ A MRI, such as ADD ,must be followed by a symbolic address.
▪ Letter I may or may not present.
▪ A symbolic address in the instruction specifies the memory location
of an operand.
▪ This location must be defined somewhere in the program by
appearing again as a label in the first column.
15
ASSEMBLY LANGUAGE…
▪ To be able to translate an assembly language program to
a binary program, it is absolutely necessary that each
symbolic address that is mention in the instruction field
must occur again in the label field.
▪ Pseudo-instruction:- is not a machine instruction, but
rather an instruction to the assembler giving information
about some phases of translation.
▪ Four pseudo-instruction that are recognized by the
assembler are :
▪ ORG N : Hexadecimal number N is the memory location for the
instruction or operand listed in the following line
▪ END : Denotes the end of symbolic program
▪ DEC N : Signed decimal number N to be converted to the binary
▪ HEX N : Hexadecimal number N to be converted to the binary 16
ASSEMBLY LANGUAGE…
▪ Comment field
▪ Comment filed must be preceded by a
slash(recognized by assembler as comment)
▪ Comments are useful for explaining the program
and are helpful in understanding the step-by-step
procedure taken by the program.
▪ Comments are inserted for explanation purpose only
and neglected during the binary translation
processes

17
ASSEMBLY LANGUAGE…
Example: Assembly language program to subtract two
numbers

What is the value stored in DIF ?


18
TRANSLATION TO BINARY CODE
▪ The translation of symbolic program into binary code is done by
assembler. This is done by scanning the program and replacing the
symbols by their machine code binary equivalent.
▪ Starting from the first line, ORG tell us to start the binary program
from hexadecimal location 10016
▪ The second line has two symbols (LDA and SUB), and since, I is
missing, the first bit of instruction is 0.
▪ From instr. Table the binary value for LDA is 2(010) and the binary
value of SUB must be obtain from the address symbol.
▪ Counting lines, we find that label SUB in line 9 corp. to memory
location 10716
▪ So the hexadecimal address of the instruction LDA must be 10716.

▪ When the two part assembled, we obtain the hexadecimal code 2107

19
TRANSLATION TO BINARY CODE…
▪ The other lines also translated in similar fashion and
their hexadecimal code is listed below

20
ADDRESS SYMBOL TABLE
▪ The translation process can be simplified if we scan the entire
symbolic program twice and, no translation is done during the first
scan
▪ We assign a memory location to each machine instruction and
operand.
▪ The location assignment will defined the address value of labels and
facilitate the translation process during the second scan
▪ In above table, we assign 100 to the first instruction after ORG.
▪ We then assign sequential location for each lines of code until END .
▪ ORG and END are not assigned a numerical location b/c they do not
represent an instruction or an operand.
▪ When the first scan is completed, we associated with each label its
location number and form a table that defines the hexadecimal value
of each symbolic address.
21
ADDRESS SYMBOL TABLE
▪ For this program, the address symbol table is shown as below

▪ During the second scan, we refer to the address symbol table to


determine the address value of a MRI.
▪ E.g.:- the line code LDA SUB is translated during the second scan
by getting the hexadecimal value of LDA = 2 from instruction table
and SUB = 107 from the address symbol of the above table.
▪ We then, assemble the two parts into a four-digits hexadecimal
instruction
▪ E.g.:- LDA SUB = 2107 four –digits hexadecimals.
22

You might also like