Docsity

Computer Organisation - PROGRAMMING THE BASIC COMPUTER, Study notes of Computer Architecture and Organization

Partial preview of the text

Download Computer Organisation - PROGRAMMING THE BASIC COMPUTER and more Study notes Computer Architecture and Organization in PDF only on Docsity!

PROGRAMMING THE BASIC

COMPUTER

INTRODUCTION

Symbol Hexa code Description

Those concerned with computer architecture should

have a knowledge of both hardware and software

because the two branches influence each other.

m: effective address M: memory word (operand) found at m Introduction AND 0 or 8 AND M to AC ADD 1 or 9 Add M to AC, carry to E LDA 2 or A Load AC from M STA 3 or B Store AC in M BUN 4 or C Branch unconditionally to m BSA 5 or D Save return address in m and branch to m+ ISZ 6 or E Increment M and skip if zero CLA 7800 Clear AC CLE 7400 Clear E CMA 7200 Complement AC CME 7100 Complement E CIR 7080 Circulate right E and AC CIL 7040 Circulate left E and AC INC 7020 Increment AC, carry to E SPA 7010 Skip if AC is positive SNA 7008 Skip if AC is negative SZA 7004 Skip if AC is zero SZE 7002 Skip if E is zero HLT 7001 Halt computer INP F800 Input information and clear flag OUT F400 Output information and clear flag SKI F200 Skip if input flag is on SKO F100 Skip if output flag is on ION F080 Turn interrupt on IOF F040 Turn interrupt off

Instruction Set of the Basic Computer

COMPARISON OF PROGRAMMING LANGUAGES

000 0010 0000 0000 0100 001 0001 0000 0000 0101 010 0011 0000 0000 0110 011 0111 0000 0000 0001 100 0000 0000 0101 0011 101 1111 1111 1110 1001 110 0000 0000 0000 0000

  • (^) Binary Program to Add Two Numbers Location Instruction Code 000 2004 001 1005 002 3006 003 7001 004 0053 005 FFE 006 0000
  • (^) Hexa program Location Instruction
  • (^) Program with Symbolic OP-Code 000 LDA 004 Load 1st operand into AC 001 ADD 005 Add 2nd operand to AC 002 STA 006 Store sum in location 006 003 HLT Halt computer 004 0053 1st operand 005 FFE9 2nd operand (negative) 006 0000 Store sum here Location Instruction Comments
  • (^) Assembly-Language Program
  • (^) C Program int A, B, C; A=83; B=-23; C = A + B; Machine Language ORG 0 /Origin of program is location 0 LDA A /Load operand from location A ADD B /Add operand from location B STA C /Store sum in location C HLT /Halt computer A, DEC 83 /Decimal operand B, DEC -23 /Decimal operand C, DEC 0 /Sum stored in location C END /End of symbolic program

ASSEMBLY LANGUAGE

yntax of the BC assembly language

Each line is arranged in three columns called fields

Label field

  • May be empty or may specify a symbolic

address consists of up to 3 characters

  • Terminated by a comma

Instruction field

  • Specifies a machine or a pseudo instruction
  • May specify one of

* Memory reference instr. (MRI)

MRI consists of two or three symbols separated by spaces.

ADD OPR (direct address MRI)

ADD PTR I (indirect address MRI)

* Register reference or input-output instr.

Non-MRI does not have an address part

* Pseudo instr. with or without an operand

Symbolic address used in the instruction field must be

defined somewhere as a label

Comment field

  • May be empty or may include a comment Assembly Language

ASSEMBLER

Assembler

Source Program - Symbolic Assembly Language Program Object Program - Binary Machine Language Program

Two pass assembler

1st pass: generates a table that correlates all user defined (address) symbols with their binary equivalent value 2nd pass: binary translation Machine instructions are translated by means of table-lookup procedures; Assembler

PROGRAM LOOPS int A[100]; int SUM; SUM = 0; For(int i=0;i<100;i++) SUM=SUM+A[i]; ORG 100 LDA ADS STA PTR LDA NBR STA CTR CLA ADD PTR I ISZ PTR ISZ CTR BUN LOP STA SUM HLT HEX 150 HEX 0 DEC - HEX 0 HEX 0 ORG 150 DEC 75 DEC 23 END / Origin of program is HEX 100 / Load first address of operand / Store in pointer / Load - / Store in counter / Clear AC / Add an operand to AC / Increment pointer / Increment counter / Repeat loop again / Store sum / Halt / First address of operands / Reserved for a pointer / Initial value for a counter / Reserved for a counter / Sum is stored here / Origin of operands is HEX 150 / First operand / Last operand / End of symbolic program LOP, ADS, PTR, NBR, CTR, SUM, Program Loops

C program to add 100 numbers:

. . .

Assembly-language program to add 100 numbers:

FLOWCHART OF A PROGRAM - Multiplication -

X holds the multiplicand Y holds the multiplier P holds the product Example with four significant digits 0000 1111 0000 1011 0000 0000 0000 1111 0000 1111 0001 1110 0010 1101 0000 0000 0010 1101 0111 1000 1010 0101 1010 0101 Programming Arithmetic and Logic Operations cil CTR  - 8 P  0 E  0 AC  Y Y  AC cir EAC E P  P + X E  0 AC  X cil EAC X  AC CTR  CTR + 1 =0 = CTR = Stop  0 X = Y = P

ASSEMBLY LANGUAGE PROGRAM - Multiplication - ORG 100 CLE LDA Y CIR STA Y SZE BUN ONE BUN ZRO LDA X ADD P STA P CLE LDA X CIL STA X ISZ CTR BUN LOP HLT DEC - HEX 000F HEX 000B HEX 0 END / Clear E / Load multiplier / Transfer multiplier bit to E / Store shifted multiplier / Check if bit is zero / Bit is one; goto ONE / Bit is zero; goto ZRO / Load multiplicand / Add to partial product / Store partial product / Clear E / Load multiplicand / Shift left / Store shifted multiplicand / Increment counter / Counter not zero; repeat loop / Counter is zero; halt / This location serves as a counter / Multiplicand stored here / Multiplier stored here / Product formed here

LOP,
ONE,
ZRO,
CTR,
X,
Y,
P,

Programming Arithmetic and Logic Operations

LDA WD

CMA

INC

ADD WD

SZA

BUN UE

BUN EL

WD1, DEC 100

WD2, DEC 200

/ Load First number

/Complement

/ increment – forms 2’s complement

/ add second word

/ skip if AC is zero

/ branch to unequal routine

/ branch to equal routine

ASSEMBLY LANGUAGE PROGRAM

  • Logic and Shift Operations -
  • (^) Logic operations
  • BC instructions : AND, CMA, CLA
  • Program for OR operation

LDA A

CMA

STA TMP

LDA B

CMA

AND TMP

CMA

/ Load 1st operand

/ Complement to get A’

/ Store in a temporary location

/ Load 2nd operand B

/ Complement to get B’

/ AND with A’ to get A’ AND B’

/ Complement again to get A OR B

  • (^) Shift operations - BC has Circular Shift only
    • Logical shift-right operation - Logical shift-left operation

CLE CLE

CIR CIL

  • Arithmetic right-shift operation

CLE

SPA

CME

CIR

/ Clear E to 0

/ Skip if AC is positive

/ AC is negative

/ Circulate E and AC

Programming Arithmetic and Logic Operations

SUBROUTINE PARAMETERS AND DATA LINKAGE
ORG 200
LDA X
BSA OR
HEX 3AF
STA Y
HLT
HEX 7B
HEX 0
HEX 0
CMA
STA TMP
LDA OR I
CMA
AND TMP
CMA
ISZ OR
BUN OR I
HEX 0
END

/ Load 1st operand into AC / Branch to subroutine OR / 2nd operand stored here / Subroutine returns here / 1st operand stored here / Result stored here / Subroutine OR / Complement 1st operand / Store in temporary location / Load 2nd operand / Complement 2nd operand / AND complemented 1st operand / Complement again to get OR / Increment return address / Return to main program / Temporary storage

X,
Y,
OR,
TMP,
20A
20B
20C
20D
20E
20F

Loc.

Example: Subroutine performing LOGICAL OR operation ; Need two parameters

Subroutines

Linkage of Parameters and Data between the Main Program and a Subroutine

  • via Registers
    • via Memory locations
  • ….

SUBROUTINE - Moving a Block of Data - BSA MVE HEX 100 HEX 200 DEC - HLT HEX 0 LDA MVE I STA PT ISZ MVE LDA MVE I STA PT ISZ MVE LDA MVE I STA CTR ISZ MVE LDA PT1 I STA PT2 I ISZ PT ISZ PT ISZ CTR BUN LOP BUN MVE I -- -- -- / Main program / Branch to subroutine / 1st address of source data / 1st address of destination data / Number of items to move / Subroutine MVE / Bring address of source / Store in 1st pointer / Increment return address / Bring address of destination / Store in 2nd pointer / Increment return address / Bring number of items / Store in counter / Increment return address / Load source item / Store in destination / Increment source pointer / Increment destination pointer / Increment counter / Repeat 16 times / Return to main program

MVE,
LOP,
PT1,
PT2,
CTR,

Subroutines

CHARACTER MANIPULATION

SKI

BUN FST

INP

OUT

BSA SH

BSA SH

SKI

BUN SCD

INP

OUT

BUN IN2 I

/ Subroutine entry

/ Input 1st character

/ Logical Shift left 4 bits

/ 4 more bits

/ Input 2nd character

/ Return

IN2,

FST,

SCD,

Subroutine to Input 2 Characters and pack into a word

Input Output Program SH4, HEX 0 CIL CIL CIL CIL AND MSK BUN SH4 I MSK, HEX FFF

AH AL

AH AL

AH AL

PROGRAM INTERRUPT

Tasks of Interrupt Service Routine

  • Save the Status of CPU

Contents of processor registers and Flags

  • Identify the source of Interrupt

Check which flag is set

  • Service the device whose flag is set

(Input Output Subroutine)

  • Restore contents of processor registers and flags
  • Turn the interrupt facility on
  • Return to the running program

Load PC of the interrupted program

Input Output Program