Programming the Basic Computer and Assembler

MitulPatel1 90 views 52 slides Jun 07, 2024
Slide 1
Slide 1 of 52
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52

About This Presentation

Assembler
Assembly Programming
Addition
Subtraction


Slide Content

Module 2
Programming the Basic Computer
By:
MitulPatel

Topics
Introduction
MachineLanguage
AssemblyLanguage
Assembler
Programloops
Programming Arithmetic and logicoperations
Subroutines
I-OProgramming

Computer Instruction
(Memory Reference Instruction)
And Memory to AC
Branch Uncondionary
Sym
AND
ADD
LDA
STA
BUN
BSA
I=0 I=1
0xxx
1xxx
2xxx
ISZ
3xxx
4xxx
5xxxDxxx
6xxx
8xxx
9xxx
Axxx
Bxxx
Cxxx
Exxx
Description
Add Memory to AC
Load To AC
Store Of AC
Return Address
Skip If Zero

Computer Instruction
(Register Reference Instruction)
7800
7400
Clear AC
Clear E
Comp. AC
Comp. E
Cir. Right AC and E
Cir. Left AC and E
Increment AC
Skip If AC is Positive
Skip If AC is Negative
Skip If AC is Zero
Skip If E is 0
Halt Computer
7200
7100
7080
7040
7020
7010
7008
7004
7002
7001
CLA
CLE
CMA
CME
CIR
CIL
INC
SPA
SNA
SZA
SZE
HLT

Computer Instruction
(Input Output Reference Instruction)
F800
F400
F200
F100
F080
F040
INP
OUT
SKI
SKO
ION
IOF
Input to AC
Output From Ac
Skip on Input Flag
Skip On Output Flag
Interrupt On
Interrupt Off

Machine Language
Program:
•A program is a list of instructionsor statements
for directing the computertoperforma
requireddata-processingtask.
•What is instructions??
•Program can be machine dependent or machine
independent.

Categories of Program
1.Binary Code
2.Octal or Hexadecimal code
3.Symbolic code
4.High-level programming language

Categories ofprograms
1.Binarycode
•Thisisasequenceofinstructionsandoperandsinbinary
thatlist the exact representation of instructions as
they appear in computermemory.
LocationInstruction Code
00010 000000000100
10001 000000000101
100011 000000000110
110111 000000000001
1000000 000001010011
1011111 111111101001
1100000 000000000000

Categories ofprograms
2. Octal or hexadecimalcode
•Thisisanequivalenttranslationofthebinarycodeto
octalor hexadecimalrepresentation.
Location Instruction
000 2004
001 1005
002 3006
003 7001
004 0053
005 FFE9
006 0000

Categories ofprograms
3. Symboliccode
•Theuseremployssymbols(letters,numerals,orspecialcharacters)forthe
operationpart,theaddresspart,andotherpartsoftheinstructioncode.
•Eachsymbolicinstructioncanbetranslatedintoonebinarycodedinstruction
byaspecialprogramcalledanassemblerandlanguageisreferredtoasan
assemblylanguageprogram.
LocationInstruction Comment
000 LDA004Load first operand intoAC
001 ADD005Add second operand toAC
002 STA006 Store sum in location006
003 HLT Haltcomputer
004 0053 Firstoperand
005 FFE9 Second operand(negative)
006 0000 Store sumhere

A.L.P to add two numbers
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 locationC
HLT /HaltComputer
A, DEC 83 /Decimaloperand
B, DEC -23 /Decimal operand
C, DEC 0 /Sum stored in location C
END /End of symbolicprogram
Module 2: Programming basic
computer

Categories ofprograms
4
.
High-level programminglanguages
•Thesearespeciallanguagesdevelopedtoreflecttheproceduresusedinthe
solutionofaproblemratherthanbeconcernedwiththecomputerhardware
behavior.E.g.Fortran,C++,Java,etc.
•Theprogramiswritteninasequenceofstatementsinaformthatpeople
prefertothinkinwhensolvingaproblem.
•However,eachstatementmustbetranslatedintoasequenceofbinary
instructionsbeforetheprogramcanbeexecutedinacomputer.
•Theprogramthattranslatesahighlevellanguageprogramtobinaryiscalleda
compiler
.
INTEGER A, B,C
DATA A, 83B,-23
C = A +B
END

ASSEMBLY LANGUAGE

Rules of the Language
•Each line of an assembly language is arranged
in three columns called fields. The fields
specify the following information:
1.The labelfield may be empty or it may
specify a symbolic address.
2.The instructionfield specifies a machine
instruction or a pseudo instruction.
3.The commentfield may be empty or it may
include a comment.

Fields of ALP
Label
(Empty/Symbo
licaddress)
Instruction
(Machine/
Pseudo)
Comment
(Empty/includecomment)
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 locationC
HLT /HaltComputer
A, DEC 83/Decimaloperand
B, DEC -23/Decimal operand
C, DEC 0 /Sum stored in location C
END /End of symbolicprogram
Module 2: Programming basic
computer

Fields of A.L.P
•The instruction field in an assembly language
program may specify one of the following
items:
1.A memory reference instruction(MRI)
2.A register-reference or input-output
instruction.(non-MRI)
3.A pseudo instruction with or without an
operand.

PseudoInstruction
•Apseudoinstructionisnotamachineinstructionbutratheran
instructiontotheassemblergivinginformationaboutsomephase
ofthetranslation.
SymbolInformation for the Assembler
ORG NHexadecimal number N is the memory location for the
instructionor operand listed in the following line
ENDDenotes the end of symbolicprogram
DEC NSigned decimal number N to be converted to binary
HEX NHexadecimal number N to be converted to binary

Instruction Field of Program
Symbol Information for the Assembler
CLA NON_MRI
ADD OPR DIRECT ADDRESS MRI
ADD PTR I INDIRECT ADDRESS MRI

Assembly language program subtract Two number
ORG100ORIGINLOCATIONIS100
LDASUBLOADTOAC
CMA COMPLEMENTAC
INC INCREMENTAC
ADDMINADDTOAC
STADIFSTOREDIFFERENCE
HLT HALTCOMPUTER
MIN,DEC83MINUEND
SUB,DEC–23SUMTRAHEND
DIF,HEX0DIFFERENCESTOREHERE
END ENDPROGRAM

translated program of subtraction
HEXADECIMAL
LOCATION CONTENT SYMBOLIC PROGRAM
ORG 100
100 2107 LDA SUB
101 7200 CMA
102 7020 INC
103 1106 ADD MIN
104 3108 STA DIF
105 7100 HLT
106 0053 MIN,DEC 83
107 FFE9 SUB, DEC -23
108 0000 DIF, HEX 0
END

A.L.P. to subtract 2numbers
Location Instruction SymbolLocation
ORG100 MIN106
100 LDASUB SUB107
101 CMA DIF108
102 INC
103 ADDMIN
104 STADIF
105 HLT
106MIN,DEC83
107SUB,DEC-23
108DIF, HEX0
END
1
2
Module 2: Programming basic
computer

Module 2: Programming basic
computer

Assembler
•An assembleris a program that accepts a symbolic
language program and produces its binary machine
language equivalent.
•The input symbolic program is called the source
program and the resultingbinaryprogramiscalled
theobjectprogram.
•The assembler is a program that operates on
character strings and produces an equivalent binary
interpretation.

Hexadecimal Character Code

Line of Code: PL3, LDA SUB I
Memory word symbol hex-code binary represent
1 PL 50 4C 0101 0000 0100 1100
2 3,33 2C 0011 0011 0010 1100
3 L D4C 44 0100 1100 0100 0100
4 A41 20 0100 0001 0010 0000
5 SU53 55 0101 0011 0101 0101
6 B42 20 0100 0010 0010 0000
7 I CR49 OD 0100 1001 0000 1100

First Pass of an Assembler
•During the first pass, it generates a table that
co-relates all user supplied address symbols
with their binary equivalent value.
•The binary translation is done during the
second pass.
•To keep track of the location of instructions,
the assembler uses a memory word called a
location counter(LC).
•Initial value of LC is given by ORG.

First Pass of anassembler
LC ←0
Scan next line ofcode
Store
addressin
symbol table
together
with value
ofLC
IncrementLC
Set
LC
ORG
END
Go to
second
pass
Firstpass
1
2
no no
no
Label
yes
yes
yes
Module 2: Programming basic
computer

Assembly language program subtract Two
number
ORG100ORIGINLOCATIONIS100
LDASUBLOADTOAC
CMA COMPLEMENTAC
INC INCREMENTAC
ADDMINADDTOAC
STADIFSTOREDIFFERENCE
HLT HALTCOMPUTER
MIN,DEC83MINUEND
SUB,DEC–23SUMTRAHEND
DIF,HEX0DIFFERENCESTOREHERE
END ENDPROGRAM

Translated Program of Subtraction
HEXADECIMAL
LOCATION CONTENT SYMBOLIC PROGRAM
ORG 100
100 2107 LDA SUB
101 7200 CMA
102 7020 INC
103 1106 ADD MIN
104 3108 STA DIF
105 7100 HLT
106 0053 MIN,DEC 83
107 FFE9 SUB, DEC -23
108 0000 DIF, HEX 0
END

A
ddress symbol Table
MEMORY
SYMBOLHEX-CODEBinaryrep.
WORD(LC)
1 MI 4D490100110101001001
2 N, 4E2C0100111000101100
3 (LC) 01060000000100000110
4 SU 53550101001101010101
5 B, 422C0100001000101100
6 (LC) 01070001000100000111
7 DI 44490100010001001001
8 F 462C0100011000101100
9 (LC) 01080000000100001000

Second Pass
•Machine instructions are translated during
the second pass by means of table-lookup
procedure.
•The assembler used four tables:
1.Pseudo instruction table.
2.MRI table
3.Non-MRI table
4.Address symbol table.

Pseudo instruction table
•Four symbols ORG,END,DEC and HEX.
•Each entry refers the assembler to a
subroutine that processes the pseudo
instruction when encountered in the
program.

MRI Table
And Memory to AC
Branch Uncondionary
Sym
AND
ADD
LDA
STA
BUN
BSA
3-bit Op-code
000
001
010
ISZ
011
100
011
110
Description
Add Memory to AC
Load To AC
Store Of AC
Return Address
Skip If Zero

Non-MRI Table
(12 Register Reference Instruction + 6 I/O reference
instruction)
7800
7400
Clear AC
Clear E
Comp. AC
Comp. E
Cir. Right AC and E
Cir. Left AC and E
Increment AC
Skip If AC is Positive
Skip If AC is Negative
Skip If AC is Zero
Skip If E is 0
Halt Computer
7200
7100
7080
7040
7020
7010
7008
7004
7002
7001
CLA
CLE
CMA
CME
CIR
CIL
INC
SPA
SNA
SZA
SZE
HLT

Non-MRI Table
(6 Input Output Reference Instruction)
F800
F400
F200
F100
F080
F040
INP
OUT
SKI
SKO
ION
IOF
Input to AC
Output From Ac
Skip on Input Flag
Skip On Output Flag
Interrupt On
Interrupt Off

Address Symbol Table
•Generated in First Pass.

Second Pass of an Assembler
•Second Pass
Module 2: Programming basic
computer

Program Loops
•What is program loop?
DIMENSION A(100)
INTEGER SUM,A
SUM = 0
DO 3 J=1,100
3SUM = SUM + A(J)

Symbolic Program to Add 100 Numbers
Location
100
101
102
103
104
105 Lop,
106
107
108
109 ADS,
110 PTR,
111 NBR,
112 CTR,
113 SUM,
114
…..
150
…..
1B3
1B4
Org 100
LDA ADS
STA PTR
LDA NBR
STA CTR
CLA
ADD PTR I
ISZ PTR
ISZ CTR
BUN LOP
HEX 150
HEX 0
DEC –100
HEX 0
HEX 0
ORG 150
……
DEC 75
DEC 23
END
/ Origin is HEX 100
/ Load First Address Of Operand
/ Store in Pointer
/ Load Minus 100
/ Store in Counter
/ Clear Ac
/ Add To Ac
/ Inc Pointer
/ Inc Counter
/ Loop Again
/ First Address Of Operand
/ Reserved for Pointer
/ Initialized Counter
/ Reserved For Counter
/ Sum is Stored Here
/Origin of operands is HEX 150
…..
/ First Operand
/Last Operand
/End of Symbolic Program

Programming Arithmetic and Logic
Operations
•Addition, Subtraction, Multiplication, Division
•AND,CMA,CLA –Logical Operations.
•Basic computer have only arithmetic instruction,
such as ADD.
•Operations that are implemented in a computer
with one machine instruction are said to be
implemented by hardware.
•Operations implemented by a set of instructions
that constitute a program are said to be
implemented by Software.
•Software implementation of arithmetic operations.

Logic Operations
•Three machine instructions: AND,CMA and CLA that
perform any logic operations.
•For example OR operation is not avaiable.
DeMorgan’sLaw: x + y = (x’y’)’
LDA A Load first operand A
CMA Complement to get A’
STA TMP Store in a temporary location
LDA B Load Second Operand B
CMA Complement to get B’
AND TMP AND with A’ to get A’^ B’
CMA Complement again to get A OR B

Shift Operations
•There are three types of shift operations: logical, rotate and
arithmetic
•Alogicalshift moves bits to the left or right.
•The bits which 'fall off' the end of the word are discarded and the
word is filled with 0's from the opposite end.
•Arotateoperation is a circular shift in which no bits are discarded.
A rotate right of the 8 bit binary number 10001011 gives
11000101, as shown below.
•An arithmetic right shift is similar to a logical right shift, except
that the leftmost bits are filled with the sign bit of the original
number instead of 0's.

Shift Operations
•Circular-Shift operations are machine
instructions in the basic computer.
•The logical shift-right operation is implemented
by:
CLE
CIR
•For logical shift-left operation
CLE
CIL

Subroutine
•A set of common instructions that can be used
in a program many times is called a subroutine.
•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.
•In the basic computer, the link between the
main program and a subroutine is a BSA
instruction.

Demonstrates the use of subroutines

Input-Output Programming
•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.

Programs to Input and Output One character
(a)InputaCharacter:
CIF,SKI/CHECKINPUTFLAG
BUNCIF/FLAG=0
INP /FLAG=1
OUT/PRINTCHARACTER
STACHR/STORECHARACTER
HLT
CHR,____/STORECHARACTER
(b)Outputonecharacter:
LDACHR/LOADINTOAC
COF,SKO/CHECKOUTPUTFLAG
BUNCOF/FLAG=0
OUT/FLAG=1
HLT
CHR,HEX0057/CHARACTERIS“W”

Program to Compare Two Words
LDAWD1/LOADFIRSTWORD
CMA
INC /FORM2’SCOMPLEMENT
ADDWD2/ADDSECONDWORD
SZA /SKIPIFACISZERO
BUNUEQ/UNEQUALROUTINE
BUNEQL/EQUALROUTINE
_____
_____
WD1,
WD2,

Exercise 1
•The following program is stored in memory unit of the basic computer.
Show the contents of AC,PC and IR(in hexadecimal) at the end, after
each instruction is executed. All numbers below are in hexadecimal.
Module 2: Programming basic
computer
Location Instruction
010 CLA
011 ADD 016
012 BUN 014
013 HLT
014 AND 017
015 BUN 013
016 C1A5
017 93C6

Exercise 2
A line of code in an assembly language program
is as follows:
DEC -35
a.Show that four memory words are required
to store the line of code and give their binary
content.
b.Show that one memory word stores the
binary translated code and give its binary
content.

Exercise 3
•Show how the MRI and Non-MRI tables can be
stored in memory.

Exercise 4
•List the assembly language program(of the
equivalent binary instructions generated by a
compiler from the following fortranprogram.
Assume integer variables.
SUM=0
SUM=SUM + A + B
DIF = DIF –C
SUM = SUM + DIF
Module 2: Programming basic
computer
Tags