SlideShare a Scribd company logo
Module 2
Programming the Basic Computer
By:
Mitul Patel
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
5xxx Dxxx
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 isalist of instructions or statements
for directing the computerto performa
required data-processingtask.
• What is instructions??
• Programcan 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 of programs
1. Binarycode
• Thisisasequenceof instructions and operandsin binary
that list the exactrepresentation of instructions as
they appear in computermemory.
Location Instruction Code
0 0010 0000 0000 0100
1 0001 0000 0000 0101
10 0011 0000 0000 0110
11 0111 0000 0000 0001
100 0000 0000 0101 0011
101 1111 1111 1110 1001
110 0000 0000 0000 0000
Categories of programs
2. Octalor hexadecimalcode
• Thisisanequivalenttranslation of the binary codeto
octalor hexadecimalrepresentation.
Location Instruction
000 2004
001 1005
002 3006
003 7001
004 0053
005 FFE9
006 0000
Categories of programs
3. Symboliccode
• The user employs symbols (letters, numerals, or special characters) for the
operationpart, the addresspart, andother partsof the instruction code.
• Each symbolic instruction can be translated into one binary coded instruction
by a special program called an assembler and language is referred to as an
assemblylanguageprogram.
Location Instruction Comment
000 LDA 004 Loadfirst operandinto AC
001 ADD 005 Addsecondoperandto AC
002 ST
A 006 Storesumin location006
003 HL
T Haltcomputer
004 0053 Firstoperand
005 FFE9 Secondoperand (negative)
006 0000 Storesumhere
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 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
Module 2: Programmingbasic
computer
Categories of programs
4. High-levelprogramminglanguages
• These are special languages developed to reflect the procedures used in the
solution of aproblem rather than be concerned with the computer hardware
behavior.E.g.Fortran, C++,Java,etc.
• The program is written in a sequence of statements in a form that people
prefer to think in when solvingaproblem.
• However, each statement must be translated into a sequence of binary
instructions before the program canbeexecutedin acomputer.
• The program that translates a high level language program to binary is called a
compiler.
INTEGER A, B, C
DATA A, 83 B,-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 label field may be empty or it may
specify a symbolic address.
2. The instruction field specifies a machine
instruction or a pseudo instruction.
3. The comment field may be empty or it may
include a comment.
Fields of ALP
Label
(Empty/Symbo
lic address)
Instruction
(Machine/
Pseudo)
Comment
(Empty/include comment)
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
Module 2: Programmingbasic
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.
Pseudo Instruction
• A pseudo instruction is not a machine instruction but rather an
instruction to the assembler giving information about some phase
of thetranslation.
Symbol Information for the Assembler
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 binary
HEX N Hexadecimal 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
ORG 100 ORIGIN LOCATION IS 100
LDA SUB LOAD TO AC
CMA COMPLEMENT AC
INC INCREMENT AC
ADD MIN ADD TO AC
STA DIF STORE DIFFERENCE
HLT HALT COMPUTER
MIN, DEC 83 MINUEND
SUB, DEC –23 SUMTRAHEND
DIF, HEX 0 DIFFERENCE STORE HERE
END END PROGRAM
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 2 numbers
Location Instruction Symbol Location
ORG100 MIN 106
100 LDASUB SUB 107
101 CMA DIF 108
102 INC
103 ADDMIN
104 ST
ADIF
105 HL
T
106 MIN, DE
C83
107 SUB, DE
C-23
108 DIF
, HEX0
END
1
2
Module 2: Programmingbasic
computer
Module 2: Programmingbasic
computer
Assembler
• Anassemblerisaprogramthat accepts asymbolic
language program and produces its binary machine
language equivalent.
• Theinput symbolic program is called the source
program and the resulting binary program is called
the object program.
• Theassembleris aprogram that operates on
character strings and producesanequivalent 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 D 4C 44 0100 1100 0100 0100
4 A 41 20 0100 0001 0010 0000
5 SU 53 55 0101 0011 0101 0101
6 B 42 20 0100 0010 0010 0000
7 I CR 49 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 an assembler
LC←0
Scannext line of code
Store
addressin
symbol table
together
with value
of LC
Increment LC
Set
LC
ORG
END
Goto
second
pass
Firstpass
1
2
no no
no
Label
yes
yes
yes
Module 2: Programmingbasic
computer
Assembly language program subtract Two
number
ORG 100 ORIGIN LOCATION IS 100
LDA SUB LOAD TO AC
CMA COMPLEMENT AC
INC INCREMENT AC
ADD MIN ADD TO AC
STA DIF STORE DIFFERENCE
HLT HALT COMPUTER
MIN, DEC 83 MINUEND
SUB, DEC –23 SUMTRAHEND
DIF, HEX 0 DIFFERENCE STORE HERE
END END PROGRAM
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
Address symbol Table
MEMORY SYMBOL HEX-CODE Binary rep.
WORD ( LC )
1 M I 4D 49 0100 1101 0100 1001
2 N , 4E 2C 0100 1110 0010 1100
3 (LC) 01 06 0000 0001 0000 0110
4 S U 53 55 0101 0011 0101 0101
5 B , 42 2C 0100 0010 0010 1100
6 (LC) 01 07 0001 0001 0000 0111
7 DI 44 49 0100 0100 0100 1001
8 F 46 2C 0100 0110 0010 1100
9 (LC) 01 08 0000 0001 0000 1000
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: Programmingbasic
computer
Program Loops
• What is program loop?
DIMENSION A(100)
INTEGER SUM,A
SUM = 0
DO 3 J=1,100
3 SUM = 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’s Law: 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
• A logical shift 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.
• A rotate operation is a circular shift in which no bits are discarded.
A rotate right of the 8 bit binary number 1000 1011 gives
1100 0101, 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) Input a Character:
CIF, SKI /CHECK INPUT FLAG
BUN CIF /FLAG=0
INP /FLAG=1
OUT /PRINT CHARACTER
STA CHR /STORE CHARACTER
HLT
CHR, ____ /STORE CHARACTER
(b) Output one character:
LDA CHR /LOAD INTO AC
COF, SKO /CHECK OUTPUT FLAG
BUN COF /FLAG=0
OUT /FLAG=1
HLT
CHR, HEX0057 /CHARACTER IS “W”
Program to Compare Two Words
LDA WD1 /LOAD FIRST WORD
CMA
INC /FORM 2’S COMPLEMENT
ADD WD2 /ADD SECOND WORD
SZA /SKIP IF AC IS ZERO
BUN UEQ /UNEQUAL ROUTINE
BUN EQL /EQUAL ROUTINE
_____
_____
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: Programmingbasic
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 fortran program.
Assume integer variables.
SUM=0
SUM=SUM + A + B
DIF = DIF – C
SUM = SUM + DIF
Module 2: Programmingbasic
computer
Ad

Recommended

Computer Organization
Computer Organization
Radhika Talaviya
 
Computer Organization - Programming the basic computer : Machine Language, As...
Computer Organization - Programming the basic computer : Machine Language, As...
Maitri Thakkar
 
Programming the basic computer
Programming the basic computer
Kamal Acharya
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Rai University
 
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
Rai University
 
Mca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed control
Rai University
 
basic computer programming and micro programmed control
basic computer programming and micro programmed control
Rai University
 
CH-3 CO-all-about-operating-system(Update).pptx
CH-3 CO-all-about-operating-system(Update).pptx
XyzXyz338506
 
Programming basic computer
Programming basic computer
Martial Kouadio
 
UNit-4.pptx programming the basic computer
UNit-4.pptx programming the basic computer
desaihardee24
 
CH06 (1).PPT
CH06 (1).PPT
RaghadAbuJelban
 
SPOS UNIT1 PPTS (1).pptx
SPOS UNIT1 PPTS (1).pptx
RavishankarBhaganaga
 
Introduction to Assembly Language & various basic things
Introduction to Assembly Language & various basic things
ishitasabrincse
 
Assembly Language Basics
Assembly Language Basics
Education Front
 
8051assembly language
8051assembly language
Hisham Mat Hussin
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
Manikandan813397
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Examinable Question and answer system programming
Examinable Question and answer system programming
Makerere university
 
Unit 3 sp assembler
Unit 3 sp assembler
Deepmala Sharma
 
Assembler
Assembler
Vaibhav Bajaj
 
microprocesser-140306112352-phpapp01.pdf
microprocesser-140306112352-phpapp01.pdf
PriyankaRana171346
 
Assembly Language Paper.docx
Assembly Language Paper.docx
write22
 
Assemblers
Assemblers
Dattatray Gandhmal
 
computer architecture Lecture 8 for computer science
computer architecture Lecture 8 for computer science
kareem mohamed
 
Assembly Language
Assembly Language
Ibrahimcommunication Al Ani
 
Unit 3 assembler and processor
Unit 3 assembler and processor
Abha Damani
 
Assembly language.pptx
Assembly language.pptx
ASHWINAIT2021
 
8085 instruction set and Programming
8085 instruction set and Programming
pooja saini
 
Complete University of Calculus :: 2nd edition
Complete University of Calculus :: 2nd edition
Shabista Imam
 
Machine Learning - Classification Algorithms
Machine Learning - Classification Algorithms
resming1
 

More Related Content

Similar to Programming the Basic Computer and Assembler (20)

Programming basic computer
Programming basic computer
Martial Kouadio
 
UNit-4.pptx programming the basic computer
UNit-4.pptx programming the basic computer
desaihardee24
 
CH06 (1).PPT
CH06 (1).PPT
RaghadAbuJelban
 
SPOS UNIT1 PPTS (1).pptx
SPOS UNIT1 PPTS (1).pptx
RavishankarBhaganaga
 
Introduction to Assembly Language & various basic things
Introduction to Assembly Language & various basic things
ishitasabrincse
 
Assembly Language Basics
Assembly Language Basics
Education Front
 
8051assembly language
8051assembly language
Hisham Mat Hussin
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
Manikandan813397
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Examinable Question and answer system programming
Examinable Question and answer system programming
Makerere university
 
Unit 3 sp assembler
Unit 3 sp assembler
Deepmala Sharma
 
Assembler
Assembler
Vaibhav Bajaj
 
microprocesser-140306112352-phpapp01.pdf
microprocesser-140306112352-phpapp01.pdf
PriyankaRana171346
 
Assembly Language Paper.docx
Assembly Language Paper.docx
write22
 
Assemblers
Assemblers
Dattatray Gandhmal
 
computer architecture Lecture 8 for computer science
computer architecture Lecture 8 for computer science
kareem mohamed
 
Assembly Language
Assembly Language
Ibrahimcommunication Al Ani
 
Unit 3 assembler and processor
Unit 3 assembler and processor
Abha Damani
 
Assembly language.pptx
Assembly language.pptx
ASHWINAIT2021
 
8085 instruction set and Programming
8085 instruction set and Programming
pooja saini
 
Programming basic computer
Programming basic computer
Martial Kouadio
 
UNit-4.pptx programming the basic computer
UNit-4.pptx programming the basic computer
desaihardee24
 
Introduction to Assembly Language & various basic things
Introduction to Assembly Language & various basic things
ishitasabrincse
 
Assembly Language Basics
Assembly Language Basics
Education Front
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Examinable Question and answer system programming
Examinable Question and answer system programming
Makerere university
 
microprocesser-140306112352-phpapp01.pdf
microprocesser-140306112352-phpapp01.pdf
PriyankaRana171346
 
Assembly Language Paper.docx
Assembly Language Paper.docx
write22
 
computer architecture Lecture 8 for computer science
computer architecture Lecture 8 for computer science
kareem mohamed
 
Unit 3 assembler and processor
Unit 3 assembler and processor
Abha Damani
 
Assembly language.pptx
Assembly language.pptx
ASHWINAIT2021
 
8085 instruction set and Programming
8085 instruction set and Programming
pooja saini
 

Recently uploaded (20)

Complete University of Calculus :: 2nd edition
Complete University of Calculus :: 2nd edition
Shabista Imam
 
Machine Learning - Classification Algorithms
Machine Learning - Classification Algorithms
resming1
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
NEW Strengthened Senior High School Gen Math.pptx
NEW Strengthened Senior High School Gen Math.pptx
DaryllWhere
 
AI_Presentation (1). Artificial intelligence
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
 
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
resming1
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
 
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
 
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
SAMEER VISHWAKARMA
 
machine learning is a advance technology
machine learning is a advance technology
ynancy893
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
Microwatt: Open Tiny Core, Big Possibilities
Microwatt: Open Tiny Core, Big Possibilities
IBM
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Mark Billinghurst
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
KhadijaKhadijaAouadi
 
How to Un-Obsolete Your Legacy Keypad Design
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
Complete University of Calculus :: 2nd edition
Complete University of Calculus :: 2nd edition
Shabista Imam
 
Machine Learning - Classification Algorithms
Machine Learning - Classification Algorithms
resming1
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
NEW Strengthened Senior High School Gen Math.pptx
NEW Strengthened Senior High School Gen Math.pptx
DaryllWhere
 
AI_Presentation (1). Artificial intelligence
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
 
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
resming1
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
 
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
 
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
SAMEER VISHWAKARMA
 
machine learning is a advance technology
machine learning is a advance technology
ynancy893
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
Microwatt: Open Tiny Core, Big Possibilities
Microwatt: Open Tiny Core, Big Possibilities
IBM
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Mark Billinghurst
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
KhadijaKhadijaAouadi
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
Ad

Programming the Basic Computer and Assembler

  • 1. Module 2 Programming the Basic Computer By: Mitul Patel
  • 3. 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 5xxx Dxxx 6xxx 8xxx 9xxx Axxx Bxxx Cxxx Exxx Description Add Memory to AC Load To AC Store Of AC Return Address Skip If Zero
  • 4. 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
  • 5. 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
  • 6. Machine Language Program: • A program isalist of instructions or statements for directing the computerto performa required data-processingtask. • What is instructions?? • Programcan be machine dependent or machine independent.
  • 7. Categories of Program 1. Binary Code 2. Octal or Hexadecimal code 3. Symbolic code 4. High-level programming language
  • 8. Categories of programs 1. Binarycode • Thisisasequenceof instructions and operandsin binary that list the exactrepresentation of instructions as they appear in computermemory. Location Instruction Code 0 0010 0000 0000 0100 1 0001 0000 0000 0101 10 0011 0000 0000 0110 11 0111 0000 0000 0001 100 0000 0000 0101 0011 101 1111 1111 1110 1001 110 0000 0000 0000 0000
  • 9. Categories of programs 2. Octalor hexadecimalcode • Thisisanequivalenttranslation of the binary codeto octalor hexadecimalrepresentation. Location Instruction 000 2004 001 1005 002 3006 003 7001 004 0053 005 FFE9 006 0000
  • 10. Categories of programs 3. Symboliccode • The user employs symbols (letters, numerals, or special characters) for the operationpart, the addresspart, andother partsof the instruction code. • Each symbolic instruction can be translated into one binary coded instruction by a special program called an assembler and language is referred to as an assemblylanguageprogram. Location Instruction Comment 000 LDA 004 Loadfirst operandinto AC 001 ADD 005 Addsecondoperandto AC 002 ST A 006 Storesumin location006 003 HL T Haltcomputer 004 0053 Firstoperand 005 FFE9 Secondoperand (negative) 006 0000 Storesumhere
  • 11. 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 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 Module 2: Programmingbasic computer
  • 12. Categories of programs 4. High-levelprogramminglanguages • These are special languages developed to reflect the procedures used in the solution of aproblem rather than be concerned with the computer hardware behavior.E.g.Fortran, C++,Java,etc. • The program is written in a sequence of statements in a form that people prefer to think in when solvingaproblem. • However, each statement must be translated into a sequence of binary instructions before the program canbeexecutedin acomputer. • The program that translates a high level language program to binary is called a compiler. INTEGER A, B, C DATA A, 83 B,-23 C = A + B END
  • 14. 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 label field may be empty or it may specify a symbolic address. 2. The instruction field specifies a machine instruction or a pseudo instruction. 3. The comment field may be empty or it may include a comment.
  • 15. Fields of ALP Label (Empty/Symbo lic address) Instruction (Machine/ Pseudo) Comment (Empty/include comment) 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 Module 2: Programmingbasic computer
  • 16. 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.
  • 17. Pseudo Instruction • A pseudo instruction is not a machine instruction but rather an instruction to the assembler giving information about some phase of thetranslation. Symbol Information for the Assembler 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 binary HEX N Hexadecimal number N to be converted to binary
  • 18. Instruction Field of Program Symbol Information for the Assembler CLA NON_MRI ADD OPR DIRECT ADDRESS MRI ADD PTR I INDIRECT ADDRESS MRI
  • 19. Assembly language program subtract Two number ORG 100 ORIGIN LOCATION IS 100 LDA SUB LOAD TO AC CMA COMPLEMENT AC INC INCREMENT AC ADD MIN ADD TO AC STA DIF STORE DIFFERENCE HLT HALT COMPUTER MIN, DEC 83 MINUEND SUB, DEC –23 SUMTRAHEND DIF, HEX 0 DIFFERENCE STORE HERE END END PROGRAM
  • 20. 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
  • 21. A.L.P. to subtract 2 numbers Location Instruction Symbol Location ORG100 MIN 106 100 LDASUB SUB 107 101 CMA DIF 108 102 INC 103 ADDMIN 104 ST ADIF 105 HL T 106 MIN, DE C83 107 SUB, DE C-23 108 DIF , HEX0 END 1 2 Module 2: Programmingbasic computer
  • 23. Assembler • Anassemblerisaprogramthat accepts asymbolic language program and produces its binary machine language equivalent. • Theinput symbolic program is called the source program and the resulting binary program is called the object program. • Theassembleris aprogram that operates on character strings and producesanequivalent binary interpretation.
  • 25. 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 D 4C 44 0100 1100 0100 0100 4 A 41 20 0100 0001 0010 0000 5 SU 53 55 0101 0011 0101 0101 6 B 42 20 0100 0010 0010 0000 7 I CR 49 OD 0100 1001 0000 1100
  • 26. 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.
  • 27. First Pass of an assembler LC←0 Scannext line of code Store addressin symbol table together with value of LC Increment LC Set LC ORG END Goto second pass Firstpass 1 2 no no no Label yes yes yes Module 2: Programmingbasic computer
  • 28. Assembly language program subtract Two number ORG 100 ORIGIN LOCATION IS 100 LDA SUB LOAD TO AC CMA COMPLEMENT AC INC INCREMENT AC ADD MIN ADD TO AC STA DIF STORE DIFFERENCE HLT HALT COMPUTER MIN, DEC 83 MINUEND SUB, DEC –23 SUMTRAHEND DIF, HEX 0 DIFFERENCE STORE HERE END END PROGRAM
  • 29. 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
  • 30. Address symbol Table MEMORY SYMBOL HEX-CODE Binary rep. WORD ( LC ) 1 M I 4D 49 0100 1101 0100 1001 2 N , 4E 2C 0100 1110 0010 1100 3 (LC) 01 06 0000 0001 0000 0110 4 S U 53 55 0101 0011 0101 0101 5 B , 42 2C 0100 0010 0010 1100 6 (LC) 01 07 0001 0001 0000 0111 7 DI 44 49 0100 0100 0100 1001 8 F 46 2C 0100 0110 0010 1100 9 (LC) 01 08 0000 0001 0000 1000
  • 31. 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.
  • 32. 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.
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. Address Symbol Table • Generated in First Pass.
  • 37. Second Pass of an Assembler • Second Pass Module 2: Programmingbasic computer
  • 38. Program Loops • What is program loop? DIMENSION A(100) INTEGER SUM,A SUM = 0 DO 3 J=1,100 3 SUM = SUM + A(J)
  • 39. 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
  • 40. 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.
  • 41. Logic Operations • Three machine instructions: AND,CMA and CLA that perform any logic operations. • For example OR operation is not avaiable. DeMorgan’s Law: 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
  • 42. Shift Operations • There are three types of shift operations: logical, rotate and arithmetic • A logical shift 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. • A rotate operation is a circular shift in which no bits are discarded. A rotate right of the 8 bit binary number 1000 1011 gives 1100 0101, 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.
  • 43. 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
  • 44. 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.
  • 45. Demonstrates the use of subroutines
  • 46. 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.
  • 47. Programs to Input and Output One character (a) Input a Character: CIF, SKI /CHECK INPUT FLAG BUN CIF /FLAG=0 INP /FLAG=1 OUT /PRINT CHARACTER STA CHR /STORE CHARACTER HLT CHR, ____ /STORE CHARACTER (b) Output one character: LDA CHR /LOAD INTO AC COF, SKO /CHECK OUTPUT FLAG BUN COF /FLAG=0 OUT /FLAG=1 HLT CHR, HEX0057 /CHARACTER IS “W”
  • 48. Program to Compare Two Words LDA WD1 /LOAD FIRST WORD CMA INC /FORM 2’S COMPLEMENT ADD WD2 /ADD SECOND WORD SZA /SKIP IF AC IS ZERO BUN UEQ /UNEQUAL ROUTINE BUN EQL /EQUAL ROUTINE _____ _____ WD1, WD2,
  • 49. 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: Programmingbasic computer Location Instruction 010 CLA 011 ADD 016 012 BUN 014 013 HLT 014 AND 017 015 BUN 013 016 C1A5 017 93C6
  • 50. 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.
  • 51. Exercise 3 • Show how the MRI and Non-MRI tables can be stored in memory.
  • 52. Exercise 4 • List the assembly language program(of the equivalent binary instructions generated by a compiler from the following fortran program. Assume integer variables. SUM=0 SUM=SUM + A + B DIF = DIF – C SUM = SUM + DIF Module 2: Programmingbasic computer