SlideShare a Scribd company logo
EE 390 Lab Manual, EE Department, KFUPM


                                    Experiment #3

                              Arithmetic Instructions


3.0 Objective

The objective of this experiment is to learn the arithmetic instructions and write simple
programs using TASM



3.1 Introduction

Arithmetic instructions provide the micro processor with its basic integer math skills. The
80x86 family provides several instructions to perform addition, subtraction,
multiplication, and division on different sizes and types of numbers. The basic set of
assembly language instructions is as follows

Addition:             ADD, ADC, INC, DAA
Subtraction:          SUB, SBB, DEC, DAS, NEG
Multiplication:       MUL, IMUL
Division:             DIV, IDIV
Sign Extension:       CBW, CWD


Examples:
                                     ADD AX,BX
adds the content of BX with AX and stores the result in AX register.

                                  ADC AX,BX
adds the content of BX, AX and the carry flag and store it in the AX register. It is
commonly used to add multibyte operands together (such as 128-bit numbers)

                                      DEC BX
decreases the content of BX register by one

                                    MUL CL
multiplies the content of CL with AL and stores the result in AX register

                                    MUL CX
multiplies the content of CX with AX and stores the 16-bit upper word in DX and 16-bit
lower word in the AX register

                                    IMUL CL
is same as MUL except that the source operand is assumed to be a signed binary number



                                                                                         1
EE 390 Lab Manual, EE Department, KFUPM


3.2 Pre-lab:

1. Write a program in TASM that performs the addition of two byte sized numbers that
   are initially stored in memory locations ‘num1’ and ‘num2’. The addition result
   should be stored in another memory location ‘total’. Verify the result using turbo
   debugger.

[Hint: Use DB directive to initially store the two byte sized numbers in memory locations
called ‘num1’ and ‘num2’. Also reserve a location for the addition result and call it
‘total’]

2. Write a program in TASM that multiplies two unsigned byte sized numbers that are
   initially stored in memory locations ‘num1’ and ‘num2’. Store the multiplication
   result in another memory location called ‘multiply’. Notice that the size of memory
   location ‘multiply’ must be of word size to be able to store the result. Verify the result
   using turbo debugger.


3.3 Lab Work:

Example Program 1: Write a program that asks to type a letter in lowercase and then
converts that letter to uppercase and also prints it on screen.

TITLE "Program to convert lowercase letter to uppercase"
.MODEL SMALL                ; this defines the memory model
.STACK 100         ; define a stack segment of 100 bytes
.DATA                       ; this is the data segment

     MSG1      DB     'Enter a lower case letter: $'
     MSG2      DB     0DH,0AH, 'The letter in uppercase is: '
     CHAR      DB      ?, '$'

.CODE                  ; this is the code segment
        ORG 100h

        MOV AX,@DATA          ; get the address of the data segment
        MOV DS,AX             ; and store it in register DS

        MOV AH,9              ; display string function
        LEA SI,MSG1           ; get memory location of first message
        MOV DX,SI              ; and store it in the DX register
        INT 21H               ; display the string

        MOV AH,01             ; single character keyboard input function
        INT 21H               ; call the function, result will be stored in AL (ASCII code)

        SUB AL,20H            ; convert to the ASCII code of upper case
        LEA SI,CHAR           ; load the address of the storage location
        MOV [SI],AL           ; store the ASCII code of the converted letter to memory


                                                                                           2
EE 390 Lab Manual, EE Department, KFUPM


        MOV AH,9              ; display string function
        LEA SI,MSG2           ; get memory location of second message
        MOV DX,SI             ; and store it in the DX register
        INT 21H               ; display the string

        MOV AX, 4C00H         ; Exit to DOS function
        INT 21H

END

String output function is used in this program to print a string on screen. The effective
address of string must first be loaded in the DX register and then the following two lines
are executed
                                      MOV AH,09
                                      INT 21H

Exercise 1: Modify the above program so that it asks for entering an uppercase letter and
converts it to lowercase.

Example Program 2: The objective of this program is to enter 3 positive numbers from
the keyboard (0-9), find the average and store the result in a memory location called
‘AVG’. Run the program in turbo debugger and verify the result.

TITLE "Program to calculate average of three numbers"
.MODEL SMALL               ; this defines the memory model
.STACK 100         ; define a stack segment of 100 bytes
.DATA                      ; this is the data segment

     msg1      DB      'Enter three numbers (0 to 9): $'
     msg2      DB     0DH,0AH,'The average is (only quotient) : $'
     num       DB     3 DUP(?)               ;memory location to store the numbers
     average   DW     ?                      ;memory location to store the average


.CODE                         ; this is the code segment
        ORG 100h              ; program starts at CS:100H

        MOV AX,@DATA          ; get the address of the data segment
        MOV DS,AX             ; and store it in register DS

        MOV CL,03             ; counter to take 3 inputs

        MOV AH,9               ; display string function
        LEA DI,msg1           ; get memory location of message1
        MOV DX,DI             ; and store it in the DX register
        INT 21H               ; display the string

        LEA SI,num            ; load the address of memory location num

START: MOV AH,01              ; single character keyboard input function


                                                                                             3
EE 390 Lab Manual, EE Department, KFUPM


      INT 21H          ; call the function, result will be stored in AL (ASCII)

      SUB AL,30H       ; subtract 30 to convert from ASCII code to number
      MOV [SI],AL      ; and store the first number in this location
      DEC CL           ; decrement CL
      CMP CL,0         ; check if the 3 inputs are complete
      JE ADD_IT        ; if yes then jump to ADD_IT location
      INC SI           ; if no then move to next location in memory
      JMP START        ; unconditional jump to get the next number

ADD_IT: MOV CL,02                ; counter to add the numbers
     LEA SI,NUM         ; get the address of the first stored number
     MOV AL,[SI]        ; store the first number in AL

AGAIN: ADD AL,[SI+1]   ; add the number with the next number
     DEC CL            ; decrease the counter
     CMP CL,0          ; if all the numbers are added
     JE DIVIDE         ; then go to the division
     INC SI            ; otherwise keep on adding the next numbers to the result
     JMP AGAIN         ; unconditional jump to add the next entry

DIVIDE: MOV AH,0       ; make AX=AL for unsigned division
     MOV CL,03         ; make divisor=3 to find average of three numbers
     DIV CL            ; divide AX by CL
     LEA SI,average    ; get the address of memory location average
     MOV [SI],AX       ; and store the result in the memory

      MOV AH,9         ; display string function
      LEA DI,msg2      ; get memory location of message1
      MOV DX,DI        ; and store it in the DX register
      INT 21H          ; display the string

      MOV DL,[SI]      ; store the result in DL
      ADD DL,30H       ; put ASCII code in DL by adding 30H
      MOV AH,02        ; display character function
      INT 21H          ; should contain ASCII code in DL

      MOV AX, 4C00H    ; Exit to DOS function
      INT 21H

END                    ; end of the program




                                                                                   4
EE 390 Lab Manual, EE Department, KFUPM


Exercise 2: Write a program in TASM that calculates the factorial of number 5 and
stores the result in a memory location. Verify the program using turbo debugger
[Hint: Since 5! = 5x4x3x2x1, use MUL instruction to find the multiplication. Store 5 in a
register and decrement the register after every multiplication and then multiply the result
with the decremented register. Repeat these steps using conditional jump instruction]

Exercise 3: Modify the factorial program such that it asks for the number for which
factorial is to be calculated using string function and keyboard input function. Assume
that the number will be less than 6 in order to fit the result in one byte.




                                                                                         5

More Related Content

PDF
N_Asm Assembly arithmetic instructions (sol)
PDF
Assembly language (coal)
PDF
Assembly language 8086
PDF
Assembly language 8086 intermediate
PDF
Instruction formats-in-8086
PDF
Chapter 6 Flow control Instructions
PDF
Unit 3 – assembly language programming
PDF
Unit 4 assembly language programming
N_Asm Assembly arithmetic instructions (sol)
Assembly language (coal)
Assembly language 8086
Assembly language 8086 intermediate
Instruction formats-in-8086
Chapter 6 Flow control Instructions
Unit 3 – assembly language programming
Unit 4 assembly language programming

What's hot (20)

PDF
Introduction to ibm pc assembly language
PDF
Alp 05
PPT
1344 Alp Of 8086
PPT
Assembly Language Lecture 5
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PDF
assembly language programming and organization of IBM PC" by YTHA YU
PPT
Assembly Language Lecture 4
PDF
8086 instructions
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
PPT
Assembly Language Lecture 1
PPTX
Multiplication & division instructions microprocessor 8086
PPTX
[ASM]Lab4
PPTX
Instruction set of 8086
PPTX
Advanced procedures in assembly language Full chapter ppt
PDF
instruction set of 8086
PPT
8086 assembly language
PDF
Assembly language part I
Introduction to ibm pc assembly language
Alp 05
1344 Alp Of 8086
Assembly Language Lecture 5
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
assembly language programming and organization of IBM PC" by YTHA YU
Assembly Language Lecture 4
8086 instructions
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Lecture 1
Multiplication & division instructions microprocessor 8086
[ASM]Lab4
Instruction set of 8086
Advanced procedures in assembly language Full chapter ppt
instruction set of 8086
8086 assembly language
Assembly language part I
Ad

Viewers also liked (20)

PPT
Slovak Consular Services in Belfast, 7 and 8 April_2014
PPTX
Introduction to building apps for windows 8
PPT
14王雨柔
PDF
PDF
Realisasi anggaran
PDF
Anggaran kas 2
PPTX
PIA AA AD16.
PDF
Радиостанция Диполь FM, Тюмень
PDF
History ofchittagongvol2
PDF
Catalogue ecobuild 2012
PPT
Repor t_text
PPTX
Presentasi modul 3 - Peralatan TI
PDF
Apakah itu Python dan bagaima setup di Window OS??
PDF
Addendum Catalogue 2013
PPT
PPT
15劉淑蓉.ptt
PPT
Presentazione mosi
PPT
KD Birmingham 5 December 2013
PDF
Emulating GCM projections by pattern scaling: performance and unforced climat...
Slovak Consular Services in Belfast, 7 and 8 April_2014
Introduction to building apps for windows 8
14王雨柔
Realisasi anggaran
Anggaran kas 2
PIA AA AD16.
Радиостанция Диполь FM, Тюмень
History ofchittagongvol2
Catalogue ecobuild 2012
Repor t_text
Presentasi modul 3 - Peralatan TI
Apakah itu Python dan bagaima setup di Window OS??
Addendum Catalogue 2013
15劉淑蓉.ptt
Presentazione mosi
KD Birmingham 5 December 2013
Emulating GCM projections by pattern scaling: performance and unforced climat...
Ad

Similar to Exp 03 (20)

PPTX
L12_ COA_COmputer architecurte and organization
PDF
PPTX
Assembly 8086
PPT
Instruction set of 8086
DOCX
Instruction set of 8086 Microprocessor
PDF
Microprocessor 8086-lab-mannual
PPTX
It322 intro 3
PPTX
DOCX
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
PPTX
Home works summary.pptx
PDF
8086 labmanual
PDF
8086 labmanual
PDF
Taller practico emu8086_galarraga
RTF
Microprocessor File
PPT
8051assembly language
PPT
Assembly language
DOCX
Microprocessor and micro-controller lab (assembly programming)
PDF
PPT
Assem -lect-6
L12_ COA_COmputer architecurte and organization
Assembly 8086
Instruction set of 8086
Instruction set of 8086 Microprocessor
Microprocessor 8086-lab-mannual
It322 intro 3
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
Home works summary.pptx
8086 labmanual
8086 labmanual
Taller practico emu8086_galarraga
Microprocessor File
8051assembly language
Assembly language
Microprocessor and micro-controller lab (assembly programming)
Assem -lect-6

Recently uploaded (20)

PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Big Data Technologies - Introduction.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Electronic commerce courselecture one. Pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Spectral efficient network and resource selection model in 5G networks
Big Data Technologies - Introduction.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
Electronic commerce courselecture one. Pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
“AI and Expert System Decision Support & Business Intelligence Systems”
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx

Exp 03

  • 1. EE 390 Lab Manual, EE Department, KFUPM Experiment #3 Arithmetic Instructions 3.0 Objective The objective of this experiment is to learn the arithmetic instructions and write simple programs using TASM 3.1 Introduction Arithmetic instructions provide the micro processor with its basic integer math skills. The 80x86 family provides several instructions to perform addition, subtraction, multiplication, and division on different sizes and types of numbers. The basic set of assembly language instructions is as follows Addition: ADD, ADC, INC, DAA Subtraction: SUB, SBB, DEC, DAS, NEG Multiplication: MUL, IMUL Division: DIV, IDIV Sign Extension: CBW, CWD Examples: ADD AX,BX adds the content of BX with AX and stores the result in AX register. ADC AX,BX adds the content of BX, AX and the carry flag and store it in the AX register. It is commonly used to add multibyte operands together (such as 128-bit numbers) DEC BX decreases the content of BX register by one MUL CL multiplies the content of CL with AL and stores the result in AX register MUL CX multiplies the content of CX with AX and stores the 16-bit upper word in DX and 16-bit lower word in the AX register IMUL CL is same as MUL except that the source operand is assumed to be a signed binary number 1
  • 2. EE 390 Lab Manual, EE Department, KFUPM 3.2 Pre-lab: 1. Write a program in TASM that performs the addition of two byte sized numbers that are initially stored in memory locations ‘num1’ and ‘num2’. The addition result should be stored in another memory location ‘total’. Verify the result using turbo debugger. [Hint: Use DB directive to initially store the two byte sized numbers in memory locations called ‘num1’ and ‘num2’. Also reserve a location for the addition result and call it ‘total’] 2. Write a program in TASM that multiplies two unsigned byte sized numbers that are initially stored in memory locations ‘num1’ and ‘num2’. Store the multiplication result in another memory location called ‘multiply’. Notice that the size of memory location ‘multiply’ must be of word size to be able to store the result. Verify the result using turbo debugger. 3.3 Lab Work: Example Program 1: Write a program that asks to type a letter in lowercase and then converts that letter to uppercase and also prints it on screen. TITLE "Program to convert lowercase letter to uppercase" .MODEL SMALL ; this defines the memory model .STACK 100 ; define a stack segment of 100 bytes .DATA ; this is the data segment MSG1 DB 'Enter a lower case letter: $' MSG2 DB 0DH,0AH, 'The letter in uppercase is: ' CHAR DB ?, '$' .CODE ; this is the code segment ORG 100h MOV AX,@DATA ; get the address of the data segment MOV DS,AX ; and store it in register DS MOV AH,9 ; display string function LEA SI,MSG1 ; get memory location of first message MOV DX,SI ; and store it in the DX register INT 21H ; display the string MOV AH,01 ; single character keyboard input function INT 21H ; call the function, result will be stored in AL (ASCII code) SUB AL,20H ; convert to the ASCII code of upper case LEA SI,CHAR ; load the address of the storage location MOV [SI],AL ; store the ASCII code of the converted letter to memory 2
  • 3. EE 390 Lab Manual, EE Department, KFUPM MOV AH,9 ; display string function LEA SI,MSG2 ; get memory location of second message MOV DX,SI ; and store it in the DX register INT 21H ; display the string MOV AX, 4C00H ; Exit to DOS function INT 21H END String output function is used in this program to print a string on screen. The effective address of string must first be loaded in the DX register and then the following two lines are executed MOV AH,09 INT 21H Exercise 1: Modify the above program so that it asks for entering an uppercase letter and converts it to lowercase. Example Program 2: The objective of this program is to enter 3 positive numbers from the keyboard (0-9), find the average and store the result in a memory location called ‘AVG’. Run the program in turbo debugger and verify the result. TITLE "Program to calculate average of three numbers" .MODEL SMALL ; this defines the memory model .STACK 100 ; define a stack segment of 100 bytes .DATA ; this is the data segment msg1 DB 'Enter three numbers (0 to 9): $' msg2 DB 0DH,0AH,'The average is (only quotient) : $' num DB 3 DUP(?) ;memory location to store the numbers average DW ? ;memory location to store the average .CODE ; this is the code segment ORG 100h ; program starts at CS:100H MOV AX,@DATA ; get the address of the data segment MOV DS,AX ; and store it in register DS MOV CL,03 ; counter to take 3 inputs MOV AH,9 ; display string function LEA DI,msg1 ; get memory location of message1 MOV DX,DI ; and store it in the DX register INT 21H ; display the string LEA SI,num ; load the address of memory location num START: MOV AH,01 ; single character keyboard input function 3
  • 4. EE 390 Lab Manual, EE Department, KFUPM INT 21H ; call the function, result will be stored in AL (ASCII) SUB AL,30H ; subtract 30 to convert from ASCII code to number MOV [SI],AL ; and store the first number in this location DEC CL ; decrement CL CMP CL,0 ; check if the 3 inputs are complete JE ADD_IT ; if yes then jump to ADD_IT location INC SI ; if no then move to next location in memory JMP START ; unconditional jump to get the next number ADD_IT: MOV CL,02 ; counter to add the numbers LEA SI,NUM ; get the address of the first stored number MOV AL,[SI] ; store the first number in AL AGAIN: ADD AL,[SI+1] ; add the number with the next number DEC CL ; decrease the counter CMP CL,0 ; if all the numbers are added JE DIVIDE ; then go to the division INC SI ; otherwise keep on adding the next numbers to the result JMP AGAIN ; unconditional jump to add the next entry DIVIDE: MOV AH,0 ; make AX=AL for unsigned division MOV CL,03 ; make divisor=3 to find average of three numbers DIV CL ; divide AX by CL LEA SI,average ; get the address of memory location average MOV [SI],AX ; and store the result in the memory MOV AH,9 ; display string function LEA DI,msg2 ; get memory location of message1 MOV DX,DI ; and store it in the DX register INT 21H ; display the string MOV DL,[SI] ; store the result in DL ADD DL,30H ; put ASCII code in DL by adding 30H MOV AH,02 ; display character function INT 21H ; should contain ASCII code in DL MOV AX, 4C00H ; Exit to DOS function INT 21H END ; end of the program 4
  • 5. EE 390 Lab Manual, EE Department, KFUPM Exercise 2: Write a program in TASM that calculates the factorial of number 5 and stores the result in a memory location. Verify the program using turbo debugger [Hint: Since 5! = 5x4x3x2x1, use MUL instruction to find the multiplication. Store 5 in a register and decrement the register after every multiplication and then multiply the result with the decremented register. Repeat these steps using conditional jump instruction] Exercise 3: Modify the factorial program such that it asks for the number for which factorial is to be calculated using string function and keyboard input function. Assume that the number will be less than 6 in order to fit the result in one byte. 5