0% found this document useful (0 votes)
15 views12 pages

Exp 3

Uploaded by

abushahzad258
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views12 pages

Exp 3

Uploaded by

abushahzad258
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Practice (Addition)

org 100h ; Start at offset 100h for .COM file compatibility


; Define variables
num1 db 10h ; First number (hexadecimal 10 = decimal 16)
num2 db 05h ; Second number (hexadecimal 05 = decimal 5)
add_result db ? ; Storage for addition result
sub_result db ? ; Storage for subtraction result
start:
; Addition
mov al, num1 ; Load num1 into AL
add al, num2 ; Add num2 to AL
mov add_result, al ; Store addition result in add_result
; Exit program
mov ax, 4C00h
int 21h
Practice (Subtraction)
org 100h ; Start at offset 100h for .COM file compatibility
; Define variables
num1 db 10h ; First number (hexadecimal 10 = decimal 16)
num2 db 05h ; Second number (hexadecimal 05 = decimal 5)
add_result db ? ; Storage for addition result
sub_result db ? ; Storage for subtraction result
start:
; Subtraction
mov al, num1 ; Reload num1 into AL
sub al, num2 ; Subtract num2 from AL
mov sub_result, al ; Store subtraction result in sub_result
; Exit program
mov ax, 4C00h
int 21h
Introduction to Input/output
• In 8086 assembly language, we use a software interrupt mechanism for I/O.
• An interrupt signals the processor to suspend its current activity (i.e.
running your program) and to pass control to an interrupt service program
(i.e. part of the operating system).
• A software interrupt is one generated by a program (as opposed to one
generated by hardware).
• The 8086 INT instruction generates a software interrupt.
• For I/O and some other operations, the number used is 21h.
• A Specific number is placed in the register AH to specify which I/O
operation (e.g. read a character, display a character) you wish to carry out.
• When the I/O operation is finished, the interrupt service program
terminates and program will be resumed at the instruction following int.
.model small
.stack 100h

.data
; Step 3: Print the character back
message db "Enter a letter: $" ; This is the text to show lea dx, newline ; Move to a new line
the user
mov ah, 09h ; Display the newline
newline db 0Dh, 0Ah, '$' ; Newline characters (go to int 21h ; Call interrupt
the next line)
mov dl, bl
.code ; Move the stored character to DL
main proc mov ah, 02h ; Function to print a character
mov ax, @data ; Initialize data segment int 21h ; Call interrupt
mov ds, ax
; Step 4: Exit the program
mov ah, 4Ch ; End the program
; Step 1: Display the message int 21h ; Call interrupt
lea dx, message ; Load the address of the message main endp
mov ah, 09h ; Function to display a string end main
int 21h ; Call interrupt (magic spell!)

; Step 2: Take a single character input


mov ah, 01h ; Function to take input
int 21h ; Call interrupt
Counter Register (CX):
• Contains the count for certain instructions e,g shift count, rotate the number
of bytes and a counter with loop instruction.
• Can be accessed as 32 bit (ECX), 16 bit (CX) or 8 bit (CH or CL) register 32 bit
• General Purpose use in ADD, MUL, DIV, MOV
• Special Purpose use in LOOP etc.
mov cl, 26 ; Loop counter (26
characters)
mov bl, 64 ; Starting ASCII value ('@',
one before 'A')

Agn: ; Move to the next line using BIOS


inc bl ; Increment to get the next mov ah, 02h ; BIOS function to set
character ('A', 'B', ...)
cursor position
mov bh, 00h ; Page number (0 for
; Print the character using DOS
default)
mov dl, bl ; Load the character into DL
inc dh ; Increment row (move
mov ah, 02h ; DOS function to print a down)
character
mov dl, 00h ; Set column to the start
int 21h ; Call DOS interrupt to display
character of the line (leftmost)
int 10h ; Call BIOS interrupt to
move cursor

loop Agn ; Loop back until CL = 0

; Exit the program


mov ah, 4Ch ; DOS terminate
program function
int 21h ; Call DOS interrupt
Tasks:
1. Write a program that input a character from user is in lowercase,
the program will convert it to uppercase and will display it on
console after conversion.
Hint: - The ASCII codes for lowercase letters (a-z) are 97-122. In order to
convert a lowercase letter to uppercase letter, just subtract 32 from its
ASCII code.
Tasks
2. Write a program that input a character from user. The program will
display it ten times on screen in newline.

3. Write a program that will display uppercase letters (A-Z), using loop
on new line.

You might also like