SlideShare a Scribd company logo
Unit - 4
r ra a
P og mming the B sic
r
Compute
Prof. Kinjal Parmar
Computer Engineering Department
A. D. Patel Institute of Technology
Mob: 8160251841
Email:cp.kinjalparmar@adit.ac.in
Computer Organization Architecture
Outline
Machine Language
Assembly Language
Assembler
Program loops
Programming Arithmetic and Logic operations
Subroutines
I-O Programming
• ar d
Bin y co e
– a r a d ra d
This is sequence of inst uctions n ope n s
ar a a r r a
in bin y th t list the ex ct ep esent tion of
r a a ar r
inst uctions s they ppe in compute
r
memo y.
a
Loc tion r d
Inst uction Co e
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
 a r ad a d
Oct l o hex ecim l co e
 a a ra a
This is n equiv lent t nsl tion of
ar d a r
the bin y co e to oct l o
ad a r r a
hex ecim l ep esent tion.
a
Loc tion r
Inst uction
000 2004
001 1005
002 3006
003 7001
004 0053
005 FFE9
006 0000
Category of Program
Category of Program
• Symbolic code
– The user employs symbols (letters, numerals, or special characters) for the
operation part, the address part, and other parts of 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
assembly language program. a
Loc tion r
Inst uction Comment
000 LDA 004 ad r ra d
Lo fi st ope n into AC
001 ADD 005 dd d ra d
A secon ope n to AC
002 STA 006 r a
Sto e sum in loc tion 006
003 HLT a r
H lt compute
004 0053 r ra d
Fi st ope n
005 FFE9 d ra d a
Secon ope n (neg tive)
006 0000 r r
Sto e sum he e
Category of Program
 High-level programming languages
 These are special languages developed to reflect the procedures used in the
solution of a problem 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 solving a problem.
 However, each statement must be translated into a sequence of binary
instructions before the program can be executed in a computer.
INTEGER A, B, C
DATA A, 83 B,-23
C = A + B
END
Pseudo Instruction
• A pseudo instruction is not a machine instruction but rather an
instruction to the assembler giving information about some phase of
the translation.
Symbol r a r r
Info m tion fo the Assemble
ORG N ad a r r a r
Hex ecim l numbe N is the memo y loc tion fo the
r r ra d d
inst uction o ope n liste in the following line.
END d r ra
Denotes the en of symbolic p og m.
DEC N d d a r r d ar
Signe ecim l numbe N to be conve te to bin y.
HEX N ad a r r d ar
Hex ecim l numbe N to be conve te to bin y
Assembler
An assembler is 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 resulting
binary program is called the object program.
The assembler is a program that operates on character strings and produces an
equivalent binary interpretation.
a
Loc tion r
Inst uction
ORG 100
100 LDA SUB
101 M
C A
102 INC
103 M
ADD IN
104 STA DIF
105 HLT
106 MIN, DEC 83
107 SUB, DEC -23
108 DIF, HEX 0
END
Symbol a
Loc tion
MIN 106
SUB 107
DIF 108
A.L.P. to subtract 2 numbers
First Pass of an assembler
LC ← 0
a d
Sc n next line of co e
a
L bel
r addr
Sto e ess in
a
symbol t ble
r
togethe with
a
v lue of LC
r
Inc ement LC
Set LC
ORG
END
Go to
d
secon
a
p ss
r a
Fi st p ss
no no
no
yes
yes
yes
First Pass of an assembler
the first pass, the assembler checks to see if the instructions are legal in the current
assembly mode.
On the first pass, the assembler performs the following tasks:
• Checks to see if the instructions are legal in the current assembly mode.
• Allocates space for instructions and storage areas you request.
• Fills in the values of constants, where possible.
• Builds a symbol table, also called a cross-reference table, and makes an entry in this
table for every symbol it encounters in the label field of a statement.
LC ← 0
a d
Sc n next line of co e
d
Pseu o-
r
inst uction
r ar
Sto e bin y
a
equiv lent of
r
inst uction in
a
loc tion given
by LC
r
Inc ement LC
Set LC
ORG END
d a
Secon p ss
Yes No
No
No
Yes Yes
Done
r
Conve t
ra d
ope n to
ar a d
bin y n
r
sto e in
a
loc tion
given by LC
MRI
No
a d
V li non-
MRI
r
inst uction
ra
Get ope tion
d a d
co e n set
bits 2-4
ar addr
Se ch ess-
a r
symbol t ble fo
ar a
bin y equiv lent of
addr
symbolic ess
a d
n set bits 5-16
I
r
Set fi st
bit to 1
r
Set fi st
bit to 0
Yes No
a ar ar
Assemble ll p ts of bin y
r a d r
inst uction n sto e in
a
loc tion given by LC
Yes
rr r
E o in
line of
d
co e
No
Yes
r
DEC o HEX
Second Pass of an assembler
Second Pass of an assembler
During the second pass, the assembler examines the operands for symbolic references to
storage locations and resolves these symbolic references using information in the symbol
table.
On the second pass, the assembler:
• Examines the operands for symbolic references to storage locations and resolves these
symbolic references using information in the symbol table.
• Ensures that no instructions contain an invalid instruction form.
• Translates source statements into machine code and constants, thus filling the
allocated space with object code.
• Produces a file containing error messages, if any have occurred.
Program Loops
• A program loop is a sequence of instructions that are executed many
times, each time with a different set of data.
• A system program that translates a program written in a high-level
programming language to a machine language program is called a
compiler.
A.L.P. to add 100 numbers
1 ORG 100 / r r ra
O igin of p og m is HEX 100
2 LDA ADS / ad r addr ra d
Lo fi st ess of ope n s
3 STA PTR / r r
Sto e in pointe
4 LDA NBR / ad
Lo minus 100
5 STA CTR / r r
Sto e in counte
6
LOP,
CLA / ar a a r
Cle ccumul to
7 ADD PTR I / dd a ra d
A n ope n to AC
8 ISZ PTR / r r
Inc ement pointe
9 ISZ CTR / r r
Inc ement counte
10 BUN LOP / a a a
Repe t loop g in
11 M
STA SU / r
Sto e sum
12 HLT / a
H lt
ADS,
13 HEX 150 / r addr ra
Fi st ess of ope n
PTR,
14 HEX 0 / a r r d
This loc tion ese ve
NBR,
15 DEC -100 / a a d
Const nt to initi lize c
CTR,
16 HEX 0 / a r r d
This loc tion ese ve
M
SU ,
17 HEX 0 / r r
Sum is sto e he e
18 ORG 150 / r ra d
O igin of ope n s is H
19 DEC 75 / r ra d
Fi st ope n
118 DEC 23 / a ra d
L st ope n
119 END / d r ra
En of symbolic p og
.
.
.
A.L.P. to Add Two Double-Precision Numbers
1 ORG 100 / r r ra
O igin of p og m is HEX 100
2 LDA AL / ad
Lo A low
3 ADD BL / dd arr
A B low, c y in E
4 STA CL / r
Sto e in C low
5 CLA / ar
Cle AC
6 CIL / r a r arr
Ci cul te to b ing c y into AC(16)
7 ADD AH / dd a d arr
A A high n c y
8 ADD BH / dd
A B high
9 STA CH / r
Sto e in C high
10 HLT / a
H lt
Subroutines
ORG 100
100 LDA X
101 BSA SH4
102 STA X
103 LDA Y
104 BSA SH4
105 STA Y
106 HLT
107 HEX 1234
X,
108 HEX 4321
Y,
109 HEX 0
10A CIL
10B CIL
10C CIL
10D CIL
10E M
AND
10F BUN S
110 HEX FF
MSK,
END
SH4,
• 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.
• A subroutine consists of a self contained
sequence of instructions that carries a given
task.
A.L.P. to input one character & output one character.
1 ORG 100 / r r ra
O igin of p og m is HEX 100
2 SKI / a
Check input fl g
3 BUN CIF / a ra a a
Fl g = 0, b nch to check g in
4 INP / a ara r
Fl g = 1, input ch cte
5 OUT / r ara r
P int ch cte
6
CHR,
STA CHR / r ara r
Sto e ch cte
7 HLT
8 - / r ara r r
Sto e ch cte he e
9 END
CIF,
1 ORG 100 / r r ra
O igin of p og m is H
2 LDA CHR / ad ara r
Lo ch cte into A
3 SKO / a
Check output fl g
4 BUN COF / a ra
Fl g = 0, b nch to ch
5 OUT / a ara
Fl g = 1, output ch
CHR,
6 HLT
7 HEX 0057 / ara r
Ch cte is “W”
8 END
COF,
r ra
Input P og m r ra
Output P og m
Booth Multiplication Algorithm
• The booth algorithm is a multiplication algorithm that allows us to multiply
the two signed binary integers in 2's complement, respectively.
• It is also used to speed up the performance of the multiplication process. It
is very efficient too.
• It works on the string bits 0's in the multiplier that requires no additional bit
only shift the right-most string bits and a string of 1's in a multiplier bit
weight 2k
to weight 2m
that can be considered as 2k+ 1
- 2m
.
UNit-4.pptx programming the basic computer
Working of Booth Algorithm
1. Set the Multiplicand and Multiplier binary bits as M and Q,
respectively.
2. Initially, we set the AC and Qn + 1 registers value to 0.
3. SC represents the number of Multiplier bits (Q), and it is a sequence
counter that is continuously decremented till equal to the number of
bits (n) or reached to 0.
4. A Qn represents the last bit of the Q, and the Qn+1 shows the
incremented bit of Qn by 1.
Working of Booth Algorithm
5. On each cycle of the booth algorithm, Qn and Qn + 1 bits will be checked on the
following parameters as follows:
• When two bits Qn and Qn + 1 are 00 or 11, we simply perform the arithmetic shift
right operation (ashr) to the partial product AC. And the bits of Qn and Qn + 1 is
incremented by 1 bit.
• If the bits of Qn and Qn + 1 is shows to 01, the multiplicand bits (M) will be added
to the AC (Accumulator register). After that, we perform the right shift operation
to the AC and QR bits by 1.
• If the bits of Qn and Qn + 1 is shows to 10, the multiplicand bits (M) will be
subtracted from the AC (Accumulator register). After that, we perform the right
Working of Booth Algorithm
6. The operation continuously works till we reached n - 1 bit in the booth
algorithm.
7.Results of the Multiplication binary bits will be stored in the AC and QR
registers.
UNit-4.pptx programming the basic computer
Ad

Recommended

Programming basic computer
Programming basic computer
Martial Kouadio
 
Programming the Basic Computer and Assembler
Programming the Basic Computer and Assembler
Mitul Patel
 
CH-3 CO-all-about-operating-system(Update).pptx
CH-3 CO-all-about-operating-system(Update).pptx
XyzXyz338506
 
Programming the basic computer
Programming the basic computer
Kamal Acharya
 
basic computer programming and micro programmed control
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
 
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
 
CH06 (1).PPT
CH06 (1).PPT
RaghadAbuJelban
 
Computer Organization and 8085 microprocessor notes
Computer Organization and 8085 microprocessor notes
Lakshmi Sarvani Videla
 
mca is a microcontroller and accmulator is a third year couse
mca is a microcontroller and accmulator is a third year couse
gauravsharma4365
 
Central processing unit pptx for computer engineering
Central processing unit pptx for computer engineering
mihirpatani5
 
Computer Architecture Assignment Help
Computer Architecture Assignment Help
Architecture Assignment Help
 
Computer Organization
Computer Organization
Radhika Talaviya
 
Unit1 C
Unit1 C
arnold 7490
 
Unit1 C
Unit1 C
arnold 7490
 
Computer organization and architecture Chapter 1 (3).PPTX
Computer organization and architecture Chapter 1 (3).PPTX
jamsibro140
 
C notes for exam preparation
C notes for exam preparation
Lakshmi Sarvani Videla
 
Chapter 4 the processor
Chapter 4 the processor
s9007912
 
UNIT-3.pptx
UNIT-3.pptx
TirthPatel479872
 
Embedded system and Internet of things-1.pptx
Embedded system and Internet of things-1.pptx
infinitynira
 
Lecture 2 coal sping12
Lecture 2 coal sping12
Rabia Khalid
 
Assembler - System Programming
Assembler - System Programming
Radhika Talaviya
 
MES_MODULE 2.pptx
MES_MODULE 2.pptx
Shivakumar M
 
Uc 2(vii)
Uc 2(vii)
Ankita Jaiswal
 
Dsp Datapath
Dsp Datapath
Abhishek Tiwari
 
cse211 power point presentation for engineering
cse211 power point presentation for engineering
VishnuVinay6
 
A Typed Assembly Language for Non-interference.pdf
A Typed Assembly Language for Non-interference.pdf
Yasmine Anino
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 

More Related Content

Similar to UNit-4.pptx programming the basic computer (20)

CH06 (1).PPT
CH06 (1).PPT
RaghadAbuJelban
 
Computer Organization and 8085 microprocessor notes
Computer Organization and 8085 microprocessor notes
Lakshmi Sarvani Videla
 
mca is a microcontroller and accmulator is a third year couse
mca is a microcontroller and accmulator is a third year couse
gauravsharma4365
 
Central processing unit pptx for computer engineering
Central processing unit pptx for computer engineering
mihirpatani5
 
Computer Architecture Assignment Help
Computer Architecture Assignment Help
Architecture Assignment Help
 
Computer Organization
Computer Organization
Radhika Talaviya
 
Unit1 C
Unit1 C
arnold 7490
 
Unit1 C
Unit1 C
arnold 7490
 
Computer organization and architecture Chapter 1 (3).PPTX
Computer organization and architecture Chapter 1 (3).PPTX
jamsibro140
 
C notes for exam preparation
C notes for exam preparation
Lakshmi Sarvani Videla
 
Chapter 4 the processor
Chapter 4 the processor
s9007912
 
UNIT-3.pptx
UNIT-3.pptx
TirthPatel479872
 
Embedded system and Internet of things-1.pptx
Embedded system and Internet of things-1.pptx
infinitynira
 
Lecture 2 coal sping12
Lecture 2 coal sping12
Rabia Khalid
 
Assembler - System Programming
Assembler - System Programming
Radhika Talaviya
 
MES_MODULE 2.pptx
MES_MODULE 2.pptx
Shivakumar M
 
Uc 2(vii)
Uc 2(vii)
Ankita Jaiswal
 
Dsp Datapath
Dsp Datapath
Abhishek Tiwari
 
cse211 power point presentation for engineering
cse211 power point presentation for engineering
VishnuVinay6
 
A Typed Assembly Language for Non-interference.pdf
A Typed Assembly Language for Non-interference.pdf
Yasmine Anino
 
Computer Organization and 8085 microprocessor notes
Computer Organization and 8085 microprocessor notes
Lakshmi Sarvani Videla
 
mca is a microcontroller and accmulator is a third year couse
mca is a microcontroller and accmulator is a third year couse
gauravsharma4365
 
Central processing unit pptx for computer engineering
Central processing unit pptx for computer engineering
mihirpatani5
 
Computer organization and architecture Chapter 1 (3).PPTX
Computer organization and architecture Chapter 1 (3).PPTX
jamsibro140
 
Chapter 4 the processor
Chapter 4 the processor
s9007912
 
Embedded system and Internet of things-1.pptx
Embedded system and Internet of things-1.pptx
infinitynira
 
Lecture 2 coal sping12
Lecture 2 coal sping12
Rabia Khalid
 
Assembler - System Programming
Assembler - System Programming
Radhika Talaviya
 
cse211 power point presentation for engineering
cse211 power point presentation for engineering
VishnuVinay6
 
A Typed Assembly Language for Non-interference.pdf
A Typed Assembly Language for Non-interference.pdf
Yasmine Anino
 

Recently uploaded (20)

Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
 
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Mark Billinghurst
 
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
 
DESIGN OF REINFORCED CONCRETE ELEMENTS S
DESIGN OF REINFORCED CONCRETE ELEMENTS S
prabhusp8
 
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
 
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Shabista Imam
 
How to Un-Obsolete Your Legacy Keypad Design
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
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
 
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
 
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
rr22001247
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
Fatality due to Falls at Working at Height
Fatality due to Falls at Working at Height
ssuserb8994f
 
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
resming1
 
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
Unit III_One Dimensional Consolidation theory
Unit III_One Dimensional Consolidation theory
saravananr808639
 
Industrial internet of things IOT Week-3.pptx
Industrial internet of things IOT Week-3.pptx
KNaveenKumarECE
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
 
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.
Mark Billinghurst
 
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
 
DESIGN OF REINFORCED CONCRETE ELEMENTS S
DESIGN OF REINFORCED CONCRETE ELEMENTS S
prabhusp8
 
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
 
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Shabista Imam
 
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
 
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
 
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
rr22001247
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
Fatality due to Falls at Working at Height
Fatality due to Falls at Working at Height
ssuserb8994f
 
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
resming1
 
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
Unit III_One Dimensional Consolidation theory
Unit III_One Dimensional Consolidation theory
saravananr808639
 
Industrial internet of things IOT Week-3.pptx
Industrial internet of things IOT Week-3.pptx
KNaveenKumarECE
 
Ad

UNit-4.pptx programming the basic computer

  • 1. Unit - 4 r ra a P og mming the B sic r Compute Prof. Kinjal Parmar Computer Engineering Department A. D. Patel Institute of Technology Mob: 8160251841 Email:[email protected] Computer Organization Architecture
  • 2. Outline Machine Language Assembly Language Assembler Program loops Programming Arithmetic and Logic operations Subroutines I-O Programming
  • 3. • ar d Bin y co e – a r a d ra d This is sequence of inst uctions n ope n s ar a a r r a in bin y th t list the ex ct ep esent tion of r a a ar r inst uctions s they ppe in compute r memo y. a Loc tion r d Inst uction Co e 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  a r ad a d Oct l o hex ecim l co e  a a ra a This is n equiv lent t nsl tion of ar d a r the bin y co e to oct l o ad a r r a hex ecim l ep esent tion. a Loc tion r Inst uction 000 2004 001 1005 002 3006 003 7001 004 0053 005 FFE9 006 0000 Category of Program
  • 4. Category of Program • Symbolic code – The user employs symbols (letters, numerals, or special characters) for the operation part, the address part, and other parts of 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 assembly language program. a Loc tion r Inst uction Comment 000 LDA 004 ad r ra d Lo fi st ope n into AC 001 ADD 005 dd d ra d A secon ope n to AC 002 STA 006 r a Sto e sum in loc tion 006 003 HLT a r H lt compute 004 0053 r ra d Fi st ope n 005 FFE9 d ra d a Secon ope n (neg tive) 006 0000 r r Sto e sum he e
  • 5. Category of Program  High-level programming languages  These are special languages developed to reflect the procedures used in the solution of a problem 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 solving a problem.  However, each statement must be translated into a sequence of binary instructions before the program can be executed in a computer. INTEGER A, B, C DATA A, 83 B,-23 C = A + B END
  • 6. Pseudo Instruction • A pseudo instruction is not a machine instruction but rather an instruction to the assembler giving information about some phase of the translation. Symbol r a r r Info m tion fo the Assemble ORG N ad a r r a r Hex ecim l numbe N is the memo y loc tion fo the r r ra d d inst uction o ope n liste in the following line. END d r ra Denotes the en of symbolic p og m. DEC N d d a r r d ar Signe ecim l numbe N to be conve te to bin y. HEX N ad a r r d ar Hex ecim l numbe N to be conve te to bin y
  • 7. Assembler An assembler is 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 resulting binary program is called the object program. The assembler is a program that operates on character strings and produces an equivalent binary interpretation.
  • 8. a Loc tion r Inst uction ORG 100 100 LDA SUB 101 M C A 102 INC 103 M ADD IN 104 STA DIF 105 HLT 106 MIN, DEC 83 107 SUB, DEC -23 108 DIF, HEX 0 END Symbol a Loc tion MIN 106 SUB 107 DIF 108 A.L.P. to subtract 2 numbers
  • 9. First Pass of an assembler LC ← 0 a d Sc n next line of co e a L bel r addr Sto e ess in a symbol t ble r togethe with a v lue of LC r Inc ement LC Set LC ORG END Go to d secon a p ss r a Fi st p ss no no no yes yes yes
  • 10. First Pass of an assembler the first pass, the assembler checks to see if the instructions are legal in the current assembly mode. On the first pass, the assembler performs the following tasks: • Checks to see if the instructions are legal in the current assembly mode. • Allocates space for instructions and storage areas you request. • Fills in the values of constants, where possible. • Builds a symbol table, also called a cross-reference table, and makes an entry in this table for every symbol it encounters in the label field of a statement.
  • 11. LC ← 0 a d Sc n next line of co e d Pseu o- r inst uction r ar Sto e bin y a equiv lent of r inst uction in a loc tion given by LC r Inc ement LC Set LC ORG END d a Secon p ss Yes No No No Yes Yes Done r Conve t ra d ope n to ar a d bin y n r sto e in a loc tion given by LC MRI No a d V li non- MRI r inst uction ra Get ope tion d a d co e n set bits 2-4 ar addr Se ch ess- a r symbol t ble fo ar a bin y equiv lent of addr symbolic ess a d n set bits 5-16 I r Set fi st bit to 1 r Set fi st bit to 0 Yes No a ar ar Assemble ll p ts of bin y r a d r inst uction n sto e in a loc tion given by LC Yes rr r E o in line of d co e No Yes r DEC o HEX Second Pass of an assembler
  • 12. Second Pass of an assembler During the second pass, the assembler examines the operands for symbolic references to storage locations and resolves these symbolic references using information in the symbol table. On the second pass, the assembler: • Examines the operands for symbolic references to storage locations and resolves these symbolic references using information in the symbol table. • Ensures that no instructions contain an invalid instruction form. • Translates source statements into machine code and constants, thus filling the allocated space with object code. • Produces a file containing error messages, if any have occurred.
  • 13. Program Loops • A program loop is a sequence of instructions that are executed many times, each time with a different set of data. • A system program that translates a program written in a high-level programming language to a machine language program is called a compiler.
  • 14. A.L.P. to add 100 numbers 1 ORG 100 / r r ra O igin of p og m is HEX 100 2 LDA ADS / ad r addr ra d Lo fi st ess of ope n s 3 STA PTR / r r Sto e in pointe 4 LDA NBR / ad Lo minus 100 5 STA CTR / r r Sto e in counte 6 LOP, CLA / ar a a r Cle ccumul to 7 ADD PTR I / dd a ra d A n ope n to AC 8 ISZ PTR / r r Inc ement pointe 9 ISZ CTR / r r Inc ement counte 10 BUN LOP / a a a Repe t loop g in 11 M STA SU / r Sto e sum 12 HLT / a H lt ADS, 13 HEX 150 / r addr ra Fi st ess of ope n PTR, 14 HEX 0 / a r r d This loc tion ese ve NBR, 15 DEC -100 / a a d Const nt to initi lize c CTR, 16 HEX 0 / a r r d This loc tion ese ve M SU , 17 HEX 0 / r r Sum is sto e he e 18 ORG 150 / r ra d O igin of ope n s is H 19 DEC 75 / r ra d Fi st ope n 118 DEC 23 / a ra d L st ope n 119 END / d r ra En of symbolic p og . . .
  • 15. A.L.P. to Add Two Double-Precision Numbers 1 ORG 100 / r r ra O igin of p og m is HEX 100 2 LDA AL / ad Lo A low 3 ADD BL / dd arr A B low, c y in E 4 STA CL / r Sto e in C low 5 CLA / ar Cle AC 6 CIL / r a r arr Ci cul te to b ing c y into AC(16) 7 ADD AH / dd a d arr A A high n c y 8 ADD BH / dd A B high 9 STA CH / r Sto e in C high 10 HLT / a H lt
  • 16. Subroutines ORG 100 100 LDA X 101 BSA SH4 102 STA X 103 LDA Y 104 BSA SH4 105 STA Y 106 HLT 107 HEX 1234 X, 108 HEX 4321 Y, 109 HEX 0 10A CIL 10B CIL 10C CIL 10D CIL 10E M AND 10F BUN S 110 HEX FF MSK, END SH4, • 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. • A subroutine consists of a self contained sequence of instructions that carries a given task.
  • 17. A.L.P. to input one character & output one character. 1 ORG 100 / r r ra O igin of p og m is HEX 100 2 SKI / a Check input fl g 3 BUN CIF / a ra a a Fl g = 0, b nch to check g in 4 INP / a ara r Fl g = 1, input ch cte 5 OUT / r ara r P int ch cte 6 CHR, STA CHR / r ara r Sto e ch cte 7 HLT 8 - / r ara r r Sto e ch cte he e 9 END CIF, 1 ORG 100 / r r ra O igin of p og m is H 2 LDA CHR / ad ara r Lo ch cte into A 3 SKO / a Check output fl g 4 BUN COF / a ra Fl g = 0, b nch to ch 5 OUT / a ara Fl g = 1, output ch CHR, 6 HLT 7 HEX 0057 / ara r Ch cte is “W” 8 END COF, r ra Input P og m r ra Output P og m
  • 18. Booth Multiplication Algorithm • The booth algorithm is a multiplication algorithm that allows us to multiply the two signed binary integers in 2's complement, respectively. • It is also used to speed up the performance of the multiplication process. It is very efficient too. • It works on the string bits 0's in the multiplier that requires no additional bit only shift the right-most string bits and a string of 1's in a multiplier bit weight 2k to weight 2m that can be considered as 2k+ 1 - 2m .
  • 20. Working of Booth Algorithm 1. Set the Multiplicand and Multiplier binary bits as M and Q, respectively. 2. Initially, we set the AC and Qn + 1 registers value to 0. 3. SC represents the number of Multiplier bits (Q), and it is a sequence counter that is continuously decremented till equal to the number of bits (n) or reached to 0. 4. A Qn represents the last bit of the Q, and the Qn+1 shows the incremented bit of Qn by 1.
  • 21. Working of Booth Algorithm 5. On each cycle of the booth algorithm, Qn and Qn + 1 bits will be checked on the following parameters as follows: • When two bits Qn and Qn + 1 are 00 or 11, we simply perform the arithmetic shift right operation (ashr) to the partial product AC. And the bits of Qn and Qn + 1 is incremented by 1 bit. • If the bits of Qn and Qn + 1 is shows to 01, the multiplicand bits (M) will be added to the AC (Accumulator register). After that, we perform the right shift operation to the AC and QR bits by 1. • If the bits of Qn and Qn + 1 is shows to 10, the multiplicand bits (M) will be subtracted from the AC (Accumulator register). After that, we perform the right
  • 22. Working of Booth Algorithm 6. The operation continuously works till we reached n - 1 bit in the booth algorithm. 7.Results of the Multiplication binary bits will be stored in the AC and QR registers.