Coal Assignment1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Task.1: Write a program in assembly language to print hello world.

Code:
include 'emu8086.inc'
org 100h
.data
.code
print "Hello World"
ret

Task.2: Write a program in assembly language to print your

 name,
 father name,
 Your study level,
 about your job?

Code:
org 100h
.data
msg1 db 13,10, "Name: Musa Jamil$"
msg2 db 13,10,"Father Name: Jamil Anwar$"
msg3 db 13,10,"Study Level: BS Computer Science$"
msg4 db 13,10,"Job: Website Developer$"
.code
main proc
mov dx, offset msg1
mov ah, 9
int 21h
mov dl, 13
mov ah, 2
int 21h
mov dl, 10
mov ah, 2
int 21h
mov dx, offset msg2
mov ah, 9
int 21h
mov dl, 13
mov ah, 2
int 21h
mov dl, 10
mov ah, 2
int 21h
mov dx, offset msg3
mov ah, 9
int 21h
mov dl, 13
mov ah, 2
int 21h
mov dl, 10
mov ah, 2
int 21h
mov dx, offset msg4
mov ah, 9
int 21h
mov dl, 13
mov ah, 2
int 21h
mov dl, 10
mov ah, 2
int 21h
main endp
end main
ret

Task.3: Write a program in assembly language to print the data in this form:
Superior 123 University 123 Lahore
Pakistan 123 Zindabad
Code:
org 100h
.data
msg1 db 10,13, "Superior",9,"123",9,"University",9,"123",9,"Lahore$"
msg2 db "Pakistan",9,"123",9,"Zindabad$"
main proc
.code
mov dx, offset msg1
mov ah, 9
int 21h
mov dl, 13
mov ah, 2
int 21h
mov dl, 10
mov ah, 2
int 21h
mov dx, offset msg2
mov ah, 9
int 21h
main endp
end main
ret

Task.4: Write a program to AND value in register.


Code:
org 100h
.model small
.stack 100h
.data
.code
Main proc
mov ax,12h
mov bx,11h
AND ax,bx
Main Endp
End main
Ret

Task.5: Write a program to add sum of two values in register


Code:
org 100h
.model small
.stack 100h
.data
.code
Main proc
mov ax, 12h
mov bx, 11h
add ax, bx
Main Endp
End main
Ret
Task.6: Write a program to make a mini calculator, Where Get firstly 2 numbers and perform
this code and also define in wording in variable string. And perform
• Add,
• subtraction,
• multiplication
• division
Code:
org 100h
.model small
.stack 100h
.data
msg1 db 10,13, "Enter 1st Number: $"
msg2 db 10,13, "Enter 2nd Number: $"
multiply db 10,13, "Multiply$"
devision db 10,13, "Devision$"
addition db 10,13, "Addition$"
substraction db 10,13, "Substraction$"
newLine db 10,13,"$"
.code
main proc
mov dx,@data
mov dx, offset msg1
mov ah,9
int 21h
mov ah,1
int 21h
mov cl,al
sub cl,'0'
mov dx, offset msg2
mov ah,9
int 21h
mov ah,1
int 21h
mov bl,al
sub bl,'0'
; Addition
mov dx,offset addition
mov ah,9
int 21h
mov dx,offset newLine
mov ah,9
int 21h
mov dl,cl
add dl,bl
add dl,48
mov ah,2
int 21h
; Substraction
mov dx,offset substraction
mov ah,9
int 21h
mov dx,offset newLine
mov ah,9
int 21h
mov dl,cl
sub dl,bl
add dl,48
mov ah,2
int 21h
; Multiplication
mov dx,offset multiply
mov ah,9
int 21h
mov dx,offset newLine
mov ah,9
int 21h
mov al,cl
mul bl
mov dl,al
add dl,48
mov ah,2
int 21h
; Devision
mov dx,offset devision
mov ah,9
int 21h
mov dx,offset newLine
mov ah,9
int 21h
mov al,cl
div bl
mov dl,al
add dl,48
mov ah,2
int 21h
main endp
end main
ret

Task.7: Increment and Decrement


Code:
org 100h
.code
main proc
mov ax, 10h
mov bx, 22h
inc ax
dec bx
end
Task.8: Print the multiple character in assembly language
Code:
.model small
.data
.code
Main proc
Mov dl, “S”
Mov ah, 2
Int 21h
Mov ah,4ch
int 21h
main endp
end main
ret

Task.9: Please remove errors in this given code?

CR equ 0DH
LF equ 0AH

main:
mov AH,02H
mov CX,26
mov DL, 'A'

while1:
cmp DL, 'A'
add DL, 01H
int 21H
mov DL, 0DH
mov DL, 0AH
int 21H
cmp DL, 'Z'
je Next
jmp while1

Next:
mov AH,4CH
int 21h

Code:
CR equ 0DH
LF equ 0AH

main:
mov AH, 02H ; Function to print a character
mov CX, 26 ; Loop counter
mov DL, 'A' ; Initial character

while1:
int 21H
inc DL ; Increment DL (character)
int 21H ; Print character
mov DL, CR ; Carriage return
int 21H ; Print CR
mov DL, LF ; Line feed
int 21H ; Print LF
cmp DL, 'Z'
je Next
jmp while1
Next:
mov AH, 4CH ; DOS program termination interrupt
int 21H

Task.10: Please remove errors in this given code?

;Math ....... A = ((B * 3) + 6) / (X + D)

mov ax,numB
mov bx,3
imul bx
add ax,6
mov bx,numX
add bx,numD
idiv bx
mov res,ax
int 21h

;Display Result

mov ax,@data
mov ds,ax
lea dx,ResPrompt
mov ah,09h
int 21h
mov ax,@data
mov ds,ax
lea dx,res
mov ah,09h
int 21h

Code:
; Assuming numB, numX, numD, and res are declared elsewhere in the program.

;Math ....... A = ((B * 3) + 6) / (X + D)

mov ax, numB ; Load numB into AX


mov bx, 3 ; Load 3 into BX
imul bx ; Multiply AX by BX
add ax, 6 ; Add 6 to AX
mov bx, numX ; Load numX into BX
add bx, numD ; Add numD to BX
idiv bx ; Divide AX by BX
mov res, ax ; Store the result in res

; Display Result
mov ah, 09h ; Function to print a string
lea dx, ResPrompt
int 21h

mov ah, 02 ; Function to print a character


mov dl, res ; Display the result
add dl, '0' ; Convert result to ASCII character
int 21h

Task.11: Print A to Z using ascii code.


Code:
org 100h
CR equ 0DH
LF equ 0AH
main:
mov AH, 02H
mov CX, 26
mov DL, 'A'
Label1:
int 21H
inc DL
cmp DL, 'Z'
jle Label1
mov AH, 02H
mov DL, CR
int 21H
mov DL, LF
int 21H
mov AH, 4CH
int 21h
ret
Task.12: program to print character.
Code:
org 100h
.model small
.data
.code
Main proc
Mov dl, "S"
Mov ah, 2
Int 21h
Mov ah,4ch
int 21h
main endp
end main
ret

Task.13: Div of two num in register


Code:
org 100h
.data
.code
mov ax, 7Ah
mov bx, 8Bh
DIV bx
Ret
Task.14: Printing values using array.
Code:
include 'emu8086.inc'
org 100h
.model small
.stack 100h
.data
arr db 3,5,7,9
.code
main proc
mov ax, @data
mov ds, ax
;for memory address of first element
mov si, offset arr
mov cx, 04 ;four elements ko move kare ga
print 'The array values are: '
display:
mov dl,[si] ;brackets lazmi lgani hain
;for output print
add dl, 48 ;for convert of ascii code
mov ah, 02 ;for output command
int 21h
;mov dl,32 ;printing space using ascii
;mov ah, 02
;int 21h
;command for next line
inc si
mov dl, 13 ;for allignment left
mov ah, 02
int 21h
mov dl, 10 ;for next line only
mov ah, 02
int 21h
loop display
main endp
end main
ret

Task.14: printing values taken from user in an array.


Code:
include 'emu8086.inc'
org 100h
.model small
.stack
.data
arr 4 dup (?) ;to enter elements from user
.code
main proc
mov ax, @data
mov ds, ax
print 'Enter the array values: '
mov si, offset arr
mov cx, 04
input:
mov ah,01 ;for user input
int 21h
mov [si], al ;move value from al to si
inc si
loop input
mov dl, 13 ;for left allign
mov ah, 02
int 21h
mov dl, 10 ;for next line
mov ah, 02
int 21h
print 'Array output values: '
mov dl, 10 ;for next line
mov ah, 02
int 21h
print '{'
mov si, offset arr
mov cx, 04
output:
mov dl, [si]
mov ah, 02
int 21h
mov dl, 32 ; output space
mov ah, 02
int 21h
inc si
loop output
print '}'
main endp
end main
ret

Task.15: Shift left register.


Code:
org 100h
.model small
.stack 100h
.data
.code
main proc
mov ax, 3h
shl ax, 1
main endp
end main
ret
Task.16: shift right register.
Code:
org 100h
.model small
.stack 100h
.data
.code
main proc
mov ax, 3h
shr ax, 1
main endp
end main
ret

Task.16: TITLE Flat Memory Program Template


Code:
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.DATA
; (insert variables here)
.CODE
main PROC
; (insert executable instructions here)
exit
main ENDP
; (insert additional procedures here)
END main

Task.17: Types of Operator.


DATA
var1 BYTE ?
var2 WORD ?
var3 DWORD ?
var4 QWORD ?
.CODE
mov eax, TYPE var1 ; eax = 1
mov eax, TYPE var2 ; eax = 2
mov eax, TYPE var3 ; eax = 4
mov eax, TYPE var4 ; eax = 8
Task.18: Length of operator.
DATA
array1 WORD 30 DUP(?),0,0
array2 WORD 5 DUP(3 DUP(?))
array3 DWORD 1,2,3,4
digitStr BYTE "12345678",0
.code
mov ecx, LENGTHOF array1 ; ecx = 32
mov ecx, LENGTHOF array2 ; ecx = 15
mov ecx, LENGTHOF array3 ; ecx = 4
mov ecx, LENGTHOF digitStr ; ecx = 9

Task.18: Size of operator


.DATA
array1 WORD 30 DUP(?),0,0
array2 WORD 5 DUP(3 DUP(?))
array3 DWORD 1,2,3,4
digitStr BYTE "12345678",0
.CODE
mov ecx, SIZEOF array1 ; ecx = 64
mov ecx, SIZEOF array2 ; ecx = 30
mov ecx, SIZEOF array3 ; ecx = 16
mov ecx, SIZEOF digitStr ; ecx = 9

Task.19: Multiple Line Decleration.


.DATA
array WORD 10,20,
30,40,
50,60
.CODE
mov eax, LENGTHOF array ; 6
mov ebx, SIZEOF array ; 12

.DATA
array WORD 10,20
WORD 30,40
WORD 50,60
.CODE
mov eax, LENGTHOF array ; 2
mov ebx, SIZEOF array ; 4

Task.20: Label Directive.


.DATA
dval LABEL DWORD
wval LABEL WORD
blist BYTE 00h,10h,00h,20h
.CODE
mov eax, dval
mov cx, wval
mov dl, blist

You might also like