SlideShare a Scribd company logo
Assembly Language Programming
Chapter 9
• Learning any imperative programming language
involves mastering a number of common concepts:
• Variables: Declaration/definition
• Assignment: Assigning values to variables
• Input/Output: Displaying messages/displaying variable values
• Control flow: Loops, JUMPs
• Subprograms: Definition and Usage
Programming in assembly language involves mastering
the same concepts and a few other issues.
Variables
• Here we will simply use the 8086 registers as
the variables in our programs.
• Registers have predefined names and do not
need to be declared.
Assignment
• In programming languages such as C/C++/Java,
assignment takes the form:
• x = 42 ;
• y = 24;
• z = x + y;
• In assembly language we carry out the same operation
but we use an instruction to denote the assignment
operator (“=”). The above assignments would be
carried out in 8086 assembly langauge as follows:
• Mov ax, 42
• Add ax, 24
• Mov bx,cx
• The mov instruction carries out assignment.
• It allows us place a number in a register or in a
memory location (a variable) i.e. it assigns a
value to a register or a variable.
Example:
• mov bx, ‘A’ To store the ASCII code for the
letter A in register bx.
• mov bx, 2  Loads the value 2 in to bx
Input/Output
• The 8086 provides the instructions IN for input
and OUT for output.
• These instructions are quite complicated to use,
so we usually use the operating system to do I/O
for us instead.
• In assembly language we must have a mechanism
to call the operating system to carry out I/O.
• In addition we must be able to tell the operating
system what kind of I/O operation we wish to
carry out, e.g. to read a character from the
keyboard, to display a character or string on the
screen, etc…...
• In 8086 assembly language, we do not call operating
system subprograms by name, instead, we use a
software interrupt mechanism
• The 8086 INT instruction generates a software interrupt.
• It uses a single operand which is a number indicating
which MS-DOS subprogram is to be invoked.
• For I/O, the number used is 21h. Thus, the instruction
INT 21h transfers control to the operating system, to a
subprogram that handles I/O operations.
• This subprogram handles a variety of I/O operations by
calling appropriate subprograms.
• This means that you must also specify which I/O
operation (e.g. read a character, display a character)
you wish to carry out. This is done by placing a specific
number in a specific register.
• The ah register is used to pass this information.
• For example, the subprogram to display a
character is subprogram number 2h.
• This number must be stored in the ah register.
• When the I/O operation is finished, the
interrupt service program terminates and our
program will be resumed.
Character Output
• There are three elements involved in carrying out this
operation using the INT instruction:
• We specify the character to be displayed. This is done by
storing the character’s ASCII code in a specific 8086
register. In this case we use the dl register, i.e. we use dl to
pass a parameter to the output subprogram.
• We specify which of MS-DOS’s I/O subprograms we wish to
use. The subprogram to display a character is subprogram
number 2h. This number is stored in the ah register.
• We request MS-DOS to carry out the I/O operation using
the INT instruction. This means that we interrupt our
program and transfer control to the MS-DOS subprogram
that we have specified using the ah register.
• Example : Write a code fragment to display
the character ’a’ on the screen:
mov dl, ‘a’ ; dl = ‘a‘
mov ah, 2h ; character output subprogram
int 21h ; call ms-dos, output character
Character Input
• There are also three elements involved in
performing character input:
• As for character output, we specify which of MS-
DOS’s I/O subprograms we wish to use, i.e. the
character input from the keyboard subprogram. This
is MS-DOS subprogram number 1h. This number
must be stored in the ah register.
• We call MS-DOS to carry out the I/O operation using
the INT instruction as for character output.
• The MS-DOS subprogram uses the al register to
store the character it reads from the keyboard.
• Example: Write a code fragment to read a
character from the keyboard
mov ah, 1h ; keyboard input subprogram
int 21h ; character input
; character is stored in al
• Example: Reading and displaying a character:
mov ah, 1h ; keyboard input subprogram
int 21h ; read character into al
mov dl, al ; copy character to dl
mov ah, 2h ; character output subprogram
int 21h ; display character in dl
A Complete 8086 Program
(Using Borland Turbo Assembler)
• Use an editor (notepad) to enter the program into a
file. We use Borland’s TASM and TLINK commands for
assembling and linking 8086 assembly language
programs. TASM program files should have names with
the extension (3 characters after period) asm.
• Let we will call our first program prog1.asm (You may
use any name you wish. It is a good practice to choose
a meaningful file name), which displays the letter ‘a’ on
the screen. Having entered and saved the program
using an editor, you must then use the TASM and TLINK
commands to translate it to machine code in the
command prompt.
Program 1:
• A complete program to display the letter ‘a’ on the screen:
• To translate the program to machine code and then go for execution,
C:> tasm prog1.asm
• If you have syntax errors, you will get error messages at this point. You then
have to edit your program, correct them and repeat the above command.
C:> tlink prog1
• To execute the program, simply enter the program name and press the Return
key:
C:> prog1
• The output of the above program will be in the screen as below:
a
C:>
• When a program has finished, we return to the
operating system.
• Like carrying out an I/O operation, this is also
accomplished by using the INT instruction. This
time MS-DOS subprogram number 4c00h is
used.
• It is the subprogram to terminate a program
and return to MS-DOS. Hence, the instructions:
mov ax, 4c00h ; Code for return to MS-DOS
int 21H ; Terminates program and return to MS-DOS.
• is a must to terminate a program code, otherwise the program
may crash
Program 2:
• Write a program to load character ’?’ into register ax and
display the same on the screen.
Program 3:
• A program to print a string ‘My First Assembly Language Program’ on the screen
• The above program can be rewritten using the
instruction LEA as follows;
• Detailed explanation of the above code:
Program 4:
• Write an interactive ALP to read a byte from the keyboard and display it on the screen
Program 5:
• Program to list all alphanumeric characters (ASCII Character Set)
(Illustration for jump instruction)
Lab Exercises Questions
• Program 6: Program to add any two hexa decimal numbers
• Program 7: Addition of any two packed BCD numbers.
• Program 8: Program to subtract packed bcd numbers
• Program 9: Program to multiply 2 numbers
• Program 10: Program to divide a packed bcd number.
• Program 11: A program to list numbers from 0,......., 9 (Illustration of Loop )
• Program 12: Program to add consecutive 10 numbers
• Program 13: Program to add any 10 stored numbers
• Program 14: Program to add any 3 numbers, entered through the
keyboard (User interactive)
• Program 15: A program that prompts the user with the question
‘Is it after 12 noon (Y/N)?’ . If the response is ‘y’ for yes , greet the
user with the message 'Good afternoon, world!’, if the response is
‘n’ for No , greet the user with the message 'Good morning,
world!’,else greet with the default message 'Good day, world!’ in a
newline. [This program will make use of ‘cmp’, ‘jmp’ instructions]
Assignment Topic
Core-i7 Processor
Things to remember while writing the assignment
• Assignment should be a hand-written one, with
maximum neatness.
• It must be submitted on January 1- 2013.
• Late submission will get your hands on a zero mark.
• The assignment should be in A4 size sheets with 4
pages only (including the cover page).
• The topics included are
 Architecture of Core-i7 (first page)
 Addressing modes of Core-i7 (second page)
 Instruction set of Core-i7 (third page)
Thank You

More Related Content

What's hot

8085 microprocessor 8155, 8255
8085 microprocessor  8155, 8255 8085 microprocessor  8155, 8255
8085 microprocessor 8155, 8255
Nitin Ahire
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
Subroutine & string in 8086 Microprocessor
Subroutine & string in 8086 MicroprocessorSubroutine & string in 8086 Microprocessor
Subroutine & string in 8086 Microprocessor
Mustafa AL-Timemmie
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
Education Front
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
karthiga selvaraju
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
Motaz Saad
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
asrithak
 
Lec 01 basic concepts
Lec 01 basic conceptsLec 01 basic concepts
Lec 01 basic concepts
Abdul Khan
 
Microprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionMicroprocessor 8086 instruction description
Microprocessor 8086 instruction description
Dheeraj Suri
 
Stack and its usage in assembly language
Stack and its usage in assembly language Stack and its usage in assembly language
Stack and its usage in assembly language
Usman Bin Saad
 
80386
8038680386
OVERVIEW OF MSP430G2553
OVERVIEW OF MSP430G2553OVERVIEW OF MSP430G2553
OVERVIEW OF MSP430G2553
shams tabrez
 
8086
80868086
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
Anwar Hasan Shuvo
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly languageMir Majid
 
Chapter 3 instruction set-of-8085
Chapter 3 instruction set-of-8085Chapter 3 instruction set-of-8085
Chapter 3 instruction set-of-8085
Shubham Singh
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
THANDAIAH PRABU
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 

What's hot (20)

8085 microprocessor 8155, 8255
8085 microprocessor  8155, 8255 8085 microprocessor  8155, 8255
8085 microprocessor 8155, 8255
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
Subroutine & string in 8086 Microprocessor
Subroutine & string in 8086 MicroprocessorSubroutine & string in 8086 Microprocessor
Subroutine & string in 8086 Microprocessor
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
 
Lec 01 basic concepts
Lec 01 basic conceptsLec 01 basic concepts
Lec 01 basic concepts
 
Microprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionMicroprocessor 8086 instruction description
Microprocessor 8086 instruction description
 
Stack and its usage in assembly language
Stack and its usage in assembly language Stack and its usage in assembly language
Stack and its usage in assembly language
 
80386
8038680386
80386
 
OVERVIEW OF MSP430G2553
OVERVIEW OF MSP430G2553OVERVIEW OF MSP430G2553
OVERVIEW OF MSP430G2553
 
8086
80868086
8086
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly language
 
Chapter 3 instruction set-of-8085
Chapter 3 instruction set-of-8085Chapter 3 instruction set-of-8085
Chapter 3 instruction set-of-8085
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 

Similar to Assembly Language Programming

Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8kapil078
 
Qbasic tutorial
Qbasic tutorialQbasic tutorial
Qbasic tutorial
jovelleluzon
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
tharwatabdulhmed
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
SREEVIDYAP10
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
MMRF2
 
Lecture01
Lecture01Lecture01
Lecture01
Xafran
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
Manikandan813397
 
Synapseindia dot net development computer programming
Synapseindia dot net development  computer programmingSynapseindia dot net development  computer programming
Synapseindia dot net development computer programming
Synapseindiappsdevelopment
 
Intro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample ProgramIntro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample Program
Blue Elephant Consulting
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Blue Elephant Consulting
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
veningstonk
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
sajjad ali khan
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
Amr Alaa El Deen
 
1.1 programming fundamentals
1.1 programming fundamentals1.1 programming fundamentals
1.1 programming fundamentals
Jawad Khan
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge
imtiazalijoono
 

Similar to Assembly Language Programming (20)

Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
Alp 05
Alp 05Alp 05
Alp 05
 
Qbasic tutorial
Qbasic tutorialQbasic tutorial
Qbasic tutorial
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Foundations of Programming Part I
Foundations of Programming Part IFoundations of Programming Part I
Foundations of Programming Part I
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Lecture01
Lecture01Lecture01
Lecture01
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
 
Synapseindia dot net development computer programming
Synapseindia dot net development  computer programmingSynapseindia dot net development  computer programming
Synapseindia dot net development computer programming
 
Intro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample ProgramIntro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample Program
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
1.1 programming fundamentals
1.1 programming fundamentals1.1 programming fundamentals
1.1 programming fundamentals
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge
 

Recently uploaded

ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 

Recently uploaded (20)

ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 

Assembly Language Programming

  • 2. • Learning any imperative programming language involves mastering a number of common concepts: • Variables: Declaration/definition • Assignment: Assigning values to variables • Input/Output: Displaying messages/displaying variable values • Control flow: Loops, JUMPs • Subprograms: Definition and Usage Programming in assembly language involves mastering the same concepts and a few other issues.
  • 3. Variables • Here we will simply use the 8086 registers as the variables in our programs. • Registers have predefined names and do not need to be declared.
  • 4. Assignment • In programming languages such as C/C++/Java, assignment takes the form: • x = 42 ; • y = 24; • z = x + y; • In assembly language we carry out the same operation but we use an instruction to denote the assignment operator (“=”). The above assignments would be carried out in 8086 assembly langauge as follows: • Mov ax, 42 • Add ax, 24 • Mov bx,cx
  • 5. • The mov instruction carries out assignment. • It allows us place a number in a register or in a memory location (a variable) i.e. it assigns a value to a register or a variable. Example: • mov bx, ‘A’ To store the ASCII code for the letter A in register bx. • mov bx, 2  Loads the value 2 in to bx
  • 6. Input/Output • The 8086 provides the instructions IN for input and OUT for output. • These instructions are quite complicated to use, so we usually use the operating system to do I/O for us instead. • In assembly language we must have a mechanism to call the operating system to carry out I/O. • In addition we must be able to tell the operating system what kind of I/O operation we wish to carry out, e.g. to read a character from the keyboard, to display a character or string on the screen, etc…...
  • 7. • In 8086 assembly language, we do not call operating system subprograms by name, instead, we use a software interrupt mechanism • The 8086 INT instruction generates a software interrupt. • It uses a single operand which is a number indicating which MS-DOS subprogram is to be invoked. • For I/O, the number used is 21h. Thus, the instruction INT 21h transfers control to the operating system, to a subprogram that handles I/O operations. • This subprogram handles a variety of I/O operations by calling appropriate subprograms. • This means that you must also specify which I/O operation (e.g. read a character, display a character) you wish to carry out. This is done by placing a specific number in a specific register.
  • 8. • The ah register is used to pass this information. • For example, the subprogram to display a character is subprogram number 2h. • This number must be stored in the ah register. • When the I/O operation is finished, the interrupt service program terminates and our program will be resumed.
  • 9. Character Output • There are three elements involved in carrying out this operation using the INT instruction: • We specify the character to be displayed. This is done by storing the character’s ASCII code in a specific 8086 register. In this case we use the dl register, i.e. we use dl to pass a parameter to the output subprogram. • We specify which of MS-DOS’s I/O subprograms we wish to use. The subprogram to display a character is subprogram number 2h. This number is stored in the ah register. • We request MS-DOS to carry out the I/O operation using the INT instruction. This means that we interrupt our program and transfer control to the MS-DOS subprogram that we have specified using the ah register.
  • 10. • Example : Write a code fragment to display the character ’a’ on the screen: mov dl, ‘a’ ; dl = ‘a‘ mov ah, 2h ; character output subprogram int 21h ; call ms-dos, output character
  • 11. Character Input • There are also three elements involved in performing character input: • As for character output, we specify which of MS- DOS’s I/O subprograms we wish to use, i.e. the character input from the keyboard subprogram. This is MS-DOS subprogram number 1h. This number must be stored in the ah register. • We call MS-DOS to carry out the I/O operation using the INT instruction as for character output. • The MS-DOS subprogram uses the al register to store the character it reads from the keyboard.
  • 12. • Example: Write a code fragment to read a character from the keyboard mov ah, 1h ; keyboard input subprogram int 21h ; character input ; character is stored in al
  • 13. • Example: Reading and displaying a character: mov ah, 1h ; keyboard input subprogram int 21h ; read character into al mov dl, al ; copy character to dl mov ah, 2h ; character output subprogram int 21h ; display character in dl
  • 14. A Complete 8086 Program (Using Borland Turbo Assembler) • Use an editor (notepad) to enter the program into a file. We use Borland’s TASM and TLINK commands for assembling and linking 8086 assembly language programs. TASM program files should have names with the extension (3 characters after period) asm. • Let we will call our first program prog1.asm (You may use any name you wish. It is a good practice to choose a meaningful file name), which displays the letter ‘a’ on the screen. Having entered and saved the program using an editor, you must then use the TASM and TLINK commands to translate it to machine code in the command prompt.
  • 15. Program 1: • A complete program to display the letter ‘a’ on the screen:
  • 16. • To translate the program to machine code and then go for execution, C:> tasm prog1.asm • If you have syntax errors, you will get error messages at this point. You then have to edit your program, correct them and repeat the above command. C:> tlink prog1 • To execute the program, simply enter the program name and press the Return key: C:> prog1 • The output of the above program will be in the screen as below: a C:>
  • 17.
  • 18. • When a program has finished, we return to the operating system. • Like carrying out an I/O operation, this is also accomplished by using the INT instruction. This time MS-DOS subprogram number 4c00h is used. • It is the subprogram to terminate a program and return to MS-DOS. Hence, the instructions: mov ax, 4c00h ; Code for return to MS-DOS int 21H ; Terminates program and return to MS-DOS. • is a must to terminate a program code, otherwise the program may crash
  • 19. Program 2: • Write a program to load character ’?’ into register ax and display the same on the screen.
  • 20. Program 3: • A program to print a string ‘My First Assembly Language Program’ on the screen
  • 21. • The above program can be rewritten using the instruction LEA as follows;
  • 22. • Detailed explanation of the above code:
  • 23.
  • 24. Program 4: • Write an interactive ALP to read a byte from the keyboard and display it on the screen
  • 25. Program 5: • Program to list all alphanumeric characters (ASCII Character Set) (Illustration for jump instruction)
  • 27. • Program 6: Program to add any two hexa decimal numbers • Program 7: Addition of any two packed BCD numbers. • Program 8: Program to subtract packed bcd numbers • Program 9: Program to multiply 2 numbers • Program 10: Program to divide a packed bcd number. • Program 11: A program to list numbers from 0,......., 9 (Illustration of Loop ) • Program 12: Program to add consecutive 10 numbers • Program 13: Program to add any 10 stored numbers • Program 14: Program to add any 3 numbers, entered through the keyboard (User interactive) • Program 15: A program that prompts the user with the question ‘Is it after 12 noon (Y/N)?’ . If the response is ‘y’ for yes , greet the user with the message 'Good afternoon, world!’, if the response is ‘n’ for No , greet the user with the message 'Good morning, world!’,else greet with the default message 'Good day, world!’ in a newline. [This program will make use of ‘cmp’, ‘jmp’ instructions]
  • 29. Things to remember while writing the assignment • Assignment should be a hand-written one, with maximum neatness. • It must be submitted on January 1- 2013. • Late submission will get your hands on a zero mark. • The assignment should be in A4 size sheets with 4 pages only (including the cover page). • The topics included are  Architecture of Core-i7 (first page)  Addressing modes of Core-i7 (second page)  Instruction set of Core-i7 (third page)