Views:
1. WAP to find even and odd number
data segment
message db 13,10,'Enter no or press "q" to quit',13,10,'$'
evn db 13, 10,'No is Even',13,10,'$'
odd db 13,10,'No is Odd',13,10,'$'
no db 02h
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
up:lea dx,message
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,'q'
jz exit
mov ah,00h
cmp al,39h
jge up
cmp al,30h
jl up
sub al,30h
div no
cmp ah,00h
jnz odd1
lea dx,evn
mov ah,09h
int 21h
jmp up
odd1:lea dx,odd
mov ah,09h
int 21h
jmp up
exit:mov ah,4ch
int 21h
code ends
end start
Output:
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#amp1#start: mov ax,data ? ax 0000 ¦c=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0000?B86D5C mov ax,5C6D ¦ bx 0000 ¦z=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#amp1#11: mov ds,ax ¦ cx 0000 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0003 8ED8 mov ds,ax ¦ dx 0000 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#amp1#up: up:lea dx,message ¦ si 0000 ¦p=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0005 BA0000 mov dx,0000 ¦ di 0000 ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#amp1#14: mov ah,09h ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0008 B409 mov ah,09 ¦ sp 0000 ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#amp1#15: int 21h ¦ ds 5C5D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:000A CD21 int 21 ¦ es 5C5D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#amp1#17: mov ah,01h ¦ ss 5C6D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:000C B401 mov ah,01 ¦ cs 5C71 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#amp1#18: int 21h ? ip 0000 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦?¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 CD 20 FF 9F 00 9A F0 FE - ƒ Ü=¦ ¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 1D F0 E4 01 14 23 AE 01 ?=S?¶#«? +----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 14 23 80 02 6F 1D DD 0E ¶#Ç?o?¦? ¦ ss:0002 6E45 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 01 01 01 00 02 FF FF FF ??? ? ¦ ss:0000?0A0D ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
+--------------------------------------------------------------+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
F1-Help F2-Bkpt F3-Mod F4-Here F5-Zoom F6-Next F7-Trace F8-Step F9-Run F10-Menu
Enter no or press "q" to quit
Enter no or press "q" to quit
-
Enter no or press "q" to quit
qTurbo Debugger Version 3.2 Copyright (c) 1988,92 Borland International
Enter no or press "q" to quit
1
No is Odd
Enter no or press "q" to quit
6
No is Even
Enter no or press "q" to quit
6
No is Even
Enter no or press "q" to quit
9
Enter no or press "q" to quit
q
----------------------------------------------------------------------------------------
2.WAP to calculate factorial of a no.
data segment
no dw 05h
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
call fact
JMP EXIT
PROC FACT
MOV ax,0000h
mov ax,no
dec no
mov bx,no
up:mul bx
dec bx
jnz up
exit:endp
code ends
end start
output:'
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#fact#15: dec no ¦ ax 0078 ¦c=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0010 FF0E0000 dec word ptr [#fa¦ bx 0002 ¦z=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#fact#16: mov bx,no ¦ cx 0000 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0014 8B1E0000 mov bx,[#fact#no]¦ dx 0000 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#fact#up: up:mul bx ¦ si 0000 ¦p=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0018 F7E3 mul bx ¦ di 0000 ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#fact#18: dec bx ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001A?4B dec bx ¦ sp FFFE ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#fact#19: jnz up ¦ ds 5C45 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001B 75FB jne #fact#up (001¦ es 5C35 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#fact#exit ¦ ss 5C45 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001D 0000 add [bx+si],al ¦ cs 5C46 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001F 00FB add bl,bh ¦ ip 001A ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦---------------------------------------------¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 04 00 00 00 00 00 00 00 ? ? ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 00 00 00 00 00 00 00 00 ¦----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 B8 45 5C 8E D8 E8 02 00 +E\Ä+F? ¦ ss:0000 0004 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 EB 13 B8 00 00 A1 00 00 d?+ í ? ss:FFFE?0008 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
+?¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?-----------------+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
F1-Help F2-Bkpt F3-Mod F4-Here F5-Zoom F6-Next F7-Trace F8-Step F9-Run F10-Menu
-------------------------------------------------------------------------------------
3a. WAP to add two 32-bit numbers
Data segment
input1 dw 0080h
input2 dw 0090h
input3 dw 0020h
input4 dw 0030h
Data ends
code segment
assume cs:code, ds:Data
start: mov ax,Data
mov ds,ax
mov ax,input1
mov cx,input2
mov bx,input3
mov dx,input4
adc ax, cx
adc bx, dx
int 03h
code ends
end start
Output:
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#amp3#18: int 03h ¦ ax 0110 ¦c=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0018?CC int 03 ¦ bx 0050 ¦z=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0019 0000 add [bx+si],al ¦ cx 0090 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001B 0000 add [bx+si],al ¦ dx 0030 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001D 0000 add [bx+si],al ¦ si 0000 ¦p=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001F 00FB add bl,bh ¦ di 0000 ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0021 52 push dx ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0022 0902 or [bp+si],ax ¦ sp 0000 ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0024 3800 cmp [bx+si],al ¦ ds 5C6B ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0026 0000 add [bx+si],al ¦ es 5C5B ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0028 07 pop es ¦ ss 5C6B ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0029 001E0000 add [#amp3#input1¦ cs 5C6C ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:002D 0005 add [di],al ¦ ip 0018 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦---------------------------------------------¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 80 00 90 00 20 00 30 00 Ç É 0 ? ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 00 00 00 00 00 00 00 00 ¦----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 B8 6B 5C 8E D8 A1 00 00 +k\Ä+í ¦ ss:0002 0090 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 8B 0E 02 00 8B 1E 04 00 ï?? ï?? ? ss:0000?0080 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
+?¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?-----------------+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
F1-Help F2-Bkpt F3-Mod F4-Here F5-Zoom F6-Next F7-Trace F8-Step F9-Run F10-Menu
---------------------------------------------------------------------------------
Data segment
n0 dw 1234h
n1 dw 1056h
n2 dw 1034h
n3 dw 1034h
result1 dw ?
result2 dw ?
Data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ax,n0
mov bx,n1
mov cx,n2
mov dx,n3
sub bx,dx
ja down
neg bx
sub ax,cx
sub ax,01h
jmp exit
down:
sub ax,cx
ja exit
neg ax
exit:mov result2,ax
mov result1,bx
int 03h
code ends
end start
Output:
╔═[■]═CPU
80486═══════════════════════════════╤═══════1═[↑][↓]═╗
╟─────────────────────────────────────────────┤
║ ds:0000 34 12 56 10 34 10 34 10 4↕V►4►4► ▲
║ ds:0008 22 00 00 02 00 00 00 00 " ☻
║ ds:0010 B8 51 5C 8E D8 A1 00 00 ╕Q\Ä╪í ▒ ss:0002 1056
║ ds:0018 8B 1E 02 00 8B 0E 04 00 ï▲☻ ï♫♦ ▼
ss:0000►12
-------------------------------------------------------------------------------------------------
3. WAP in ALP to add and subtract two 32 bit numbers
Data segment
input1 dw 0080h
input2 dw 0090h
input3 dw 0020h
input4 dw 0030h
Data ends
code segment
assume cs:code, ds:Data
start:
mov ax,Data
mov ds,ax
mov ax,0080h
adc ax, 0020h
mov bx, 0090h
add bx, 0030h
mov cx, 0080h
sub cx, 0020h
mov dx, 0090h
sub dx, 0030h
int 03h
code ends
end start
4. WAP in ALP to find whether a number is prime or not
data segment
cr equ 0dh
lf equ 0ah
str1 db cr,lf,'Enter a number',cr,lf,'$'
str2 db cr,lf,'Number is prime',cr,lf,'$'
str3 db cr,lf,'Number is not prime',cr,lf,'$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
up: mov dx,offset str1
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,'q'
jz exit
sub al,30h
cmp al,01h
jz prime
mov bl,01h
mov dl,al
l1:inc bl
cmp dl,bl
jz prime
mov ah,00h
div bl
cmp ah,00h
jz np
mov al,dl
jmp l1
prime:mov dx,offset str2
mov ah,09h
int 21h
jmp up
np: mov dx,offset str3
mov ah,09h
int 21h
jmp up
exit:mov ah,4ch
int 21h
code ends
end start
OUTPUT:
Enter a number
0
Number is not prime
Enter a number
1
Number is prime
Enter a number
2
Number is prime
Enter a number
3
Number is prime
Enter a number
4
Number is not prime
Enter a number
5
Number is prime
Enter a number
6
Number is not prime
Enter a number
7
Number is prime
Enter a number
8
Number is not prime
Enter a number
9
Number is not prime
Enter a number
q
-------------------------------------------------------------------------------------
5. WAP in ALP to sort a list of numbers
data segment
source db 15h,10h,24h,13h,55h,16h,11h,20h,21h,12h
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov ch,09h
up1: lea si,source
lea di,source
inc di
mov cl,09h
up: mov dl,[di]
cmp [si],dl
jb down
xchg [si],dl
mov [di],dl
down:
inc si
inc di
dec cl
jnz up
dec ch
jnz up1
int 03h
code ends
end start
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#bubble#25: int 03h ¦ ax 5C3D ¦c=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0024?CC int 03 ¦ bx 0000 ¦z=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0025 0000 add [bx+si],al ¦ cx 0000 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0027 0000 add [bx+si],al ¦ dx 0055 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0029 0000 add [bx+si],al ¦ si 0009 ¦p=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:002B 0000 add [bx+si],al ¦ di 000A ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:002D 0000 add [bx+si],al ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:002F 00FB add bl,bh ¦ sp 0000 ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0031 52 push dx ¦ ds 5C3D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0032 0902 or [bp+si],ax ¦ es 5C2D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0034 3300 xor ax,[bx+si] ¦ ss 5C3D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0036 0000 add [bx+si],al ¦ cs 5C3E ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0038 07 pop es ¦ ip 0024 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦---------------------------------------------¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 10 11 12 13 15 16 20 21 ????§? ! ? ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 24 55 00 00 00 00 00 00 $U ¦----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 B8 3D 5C 8E D8 B5 09 BE +=\Ä+¦?+ ¦ ss:0002 1312 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 00 00 BF 00 00 47 B1 09 + G¦? ? ss:0000?1110 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
+?¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?-----------------+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
Alt: F2-Bkpt at F3-Close F4-Back F5-User F6-Undo F7-Instr F8-Rtn F9-To F10-Local
------------------------------------------------------------------------------------------------------
6.a. WAP in ALP to add two 16 bit numbers
data segment
no1 dw 24H
no2 dw 16H
carry dw ?
result dw ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,no1
add ax,no2
mov result,ax
jc down
mov carry,0000H
down:mov carry,0001H
exit:
int 03H
code ends
end start
Output:
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#zain16ad#16: mov carry,0000H ¦ ax 003A ¦c=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0011?C70604000000 mov word ptr [#za¦ bx 0000 ¦z=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#zain16ad#down: down:mov carry,0001H ¦ cx 0000 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0017 C70604000100 mov word ptr [#za¦ dx 0000 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#zain16ad#exit: int 03H ¦ si 0000 ¦p=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001D CC int 03 ¦ di 0000 ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001E 0000 add [bx+si],al ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0020 FB sti ¦ sp 0000 ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0021 52 push dx ¦ ds 5C6F ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0022 0902 or [bp+si],ax ¦ es 5C5F ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0024 43 inc bx ¦ ss 5C6F ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0025 0000 add [bx+si],al ¦ cs 5C70 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0027 0009 add [bx+di],cl ¦ ip 0011 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦---------------------------------------------¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 24 00 16 00 00 00 3A 00 $ ? : ? ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 00 00 00 00 00 00 00 00 ¦----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 B8 6F 5C 8E D8 A1 00 00 +o\Ä+í ¦ ss:0002 0016 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 03 06 02 00 A3 06 00 72 ??? ú? r ? ss:0000?0024 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
+?¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
-------------------------------------------------------------------------------
6.b. WAP in ALP to subtract two 16 bit numbers
data segment
no1 dw 19h
no2 dw 16H
result dw ?
data ends
code segment
assume ds:data, cs:code
start: mov ax,data
mov ds,ax
mov ax,no1
sub ax,no2
mov result,ax
int 03h
code ends
end start
output:
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#start: start: mov ax,data ¦ ax 0003 ¦c=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0000 B8645C mov ax,5C64 ¦ bx 0000 ¦z=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#10: mov ds,ax ¦ cx 0000 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0003 8ED8 mov ds,ax ¦ dx 0000 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#11: mov ax,no1 ¦ si 0000 ¦p=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0005 A10000 mov ax,[#sub#no1]¦ di 0000 ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#12: sub ax,no2 ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0008 2B060200 sub ax,[#sub#no2]¦ sp 0000 ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#13: mov result,ax ¦ ds 5C64 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:000C?A30400 mov [#sub#result]¦ es 5C54 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#14: int 03h ¦ ss 5C64 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:000F CC int 03 ¦ cs 5C65 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0010 FB sti ¦ ip 000C ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦---------------------------------------------¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 19 00 16 00 00 00 00 00 ? ? ? ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 00 00 00 00 00 00 00 00 ¦----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 B8 64 5C 8E D8 A1 00 00 +d\Ä+í ¦ ss:0002 0016 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 2B 06 02 00 A3 04 00 CC +?? ú? ¦ ? ss:0000?0019 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
-----------------------------------------------------------------------------------------------
6. WAP in ALP to add and subtract two 16-bit numbers
------------------------------------------------------------------------------------------------------
3. WAP in ALP to add and subtract two 32 bit numbers
Data segment
input1 dw 0080h
input2 dw 0090h
input3 dw 0020h
input4 dw 0030h
Data ends
code segment
assume cs:code, ds:Data
start:
mov ax,Data
mov ds,ax
mov ax,0080h
adc ax, 0020h
mov bx, 0090h
add bx, 0030h
mov cx, 0080h
sub cx, 0020h
mov dx, 0090h
sub dx, 0030h
int 03h
code ends
end start
------------------------------------------------------------------------------------
4. WAP in ALP to find whether a number is prime or not
data segment
cr equ 0dh
lf equ 0ah
str1 db cr,lf,'Enter a number',cr,lf,'$'
str2 db cr,lf,'Number is prime',cr,lf,'$'
str3 db cr,lf,'Number is not prime',cr,lf,'$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
up: mov dx,offset str1
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,'q'
jz exit
sub al,30h
cmp al,01h
jz prime
mov bl,01h
mov dl,al
l1:inc bl
cmp dl,bl
jz prime
mov ah,00h
div bl
cmp ah,00h
jz np
mov al,dl
jmp l1
prime:mov dx,offset str2
mov ah,09h
int 21h
jmp up
np: mov dx,offset str3
mov ah,09h
int 21h
jmp up
exit:mov ah,4ch
int 21h
code ends
end start
OUTPUT:
Enter a number
0
Number is not prime
Enter a number
1
Number is prime
Enter a number
2
Number is prime
Enter a number
3
Number is prime
Enter a number
4
Number is not prime
Enter a number
5
Number is prime
Enter a number
6
Number is not prime
Enter a number
7
Number is prime
Enter a number
8
Number is not prime
Enter a number
9
Number is not prime
Enter a number
q
-------------------------------------------------------------------------------------
5. WAP in ALP to sort a list of numbers
data segment
source db 15h,10h,24h,13h,55h,16h,11h,20h,21h,12h
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov ch,09h
up1: lea si,source
lea di,source
inc di
mov cl,09h
up: mov dl,[di]
cmp [si],dl
jb down
xchg [si],dl
mov [di],dl
down:
inc si
inc di
dec cl
jnz up
dec ch
jnz up1
int 03h
code ends
end start
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#bubble#25: int 03h ¦ ax 5C3D ¦c=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0024?CC int 03 ¦ bx 0000 ¦z=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0025 0000 add [bx+si],al ¦ cx 0000 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0027 0000 add [bx+si],al ¦ dx 0055 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0029 0000 add [bx+si],al ¦ si 0009 ¦p=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:002B 0000 add [bx+si],al ¦ di 000A ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:002D 0000 add [bx+si],al ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:002F 00FB add bl,bh ¦ sp 0000 ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0031 52 push dx ¦ ds 5C3D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0032 0902 or [bp+si],ax ¦ es 5C2D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0034 3300 xor ax,[bx+si] ¦ ss 5C3D ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0036 0000 add [bx+si],al ¦ cs 5C3E ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0038 07 pop es ¦ ip 0024 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦---------------------------------------------¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 10 11 12 13 15 16 20 21 ????§? ! ? ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 24 55 00 00 00 00 00 00 $U ¦----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 B8 3D 5C 8E D8 B5 09 BE +=\Ä+¦?+ ¦ ss:0002 1312 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 00 00 BF 00 00 47 B1 09 + G¦? ? ss:0000?1110 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
+?¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦?-----------------+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
Alt: F2-Bkpt at F3-Close F4-Back F5-User F6-Undo F7-Instr F8-Rtn F9-To F10-Local
------------------------------------------------------------------------------------------------------
6.a. WAP in ALP to add two 16 bit numbers
data segment
no1 dw 24H
no2 dw 16H
carry dw ?
result dw ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,no1
add ax,no2
mov result,ax
jc down
mov carry,0000H
down:mov carry,0001H
exit:
int 03H
code ends
end start
Output:
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#zain16ad#16: mov carry,0000H ¦ ax 003A ¦c=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0011?C70604000000 mov word ptr [#za¦ bx 0000 ¦z=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#zain16ad#down: down:mov carry,0001H ¦ cx 0000 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0017 C70604000100 mov word ptr [#za¦ dx 0000 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#zain16ad#exit: int 03H ¦ si 0000 ¦p=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001D CC int 03 ¦ di 0000 ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:001E 0000 add [bx+si],al ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0020 FB sti ¦ sp 0000 ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0021 52 push dx ¦ ds 5C6F ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0022 0902 or [bp+si],ax ¦ es 5C5F ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0024 43 inc bx ¦ ss 5C6F ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0025 0000 add [bx+si],al ¦ cs 5C70 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0027 0009 add [bx+di],cl ¦ ip 0011 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦---------------------------------------------¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 24 00 16 00 00 00 3A 00 $ ? : ? ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 00 00 00 00 00 00 00 00 ¦----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 B8 6F 5C 8E D8 A1 00 00 +o\Ä+í ¦ ss:0002 0016 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 03 06 02 00 A3 06 00 72 ??? ú? r ? ss:0000?0024 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
+?¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
-------------------------------------------------------------------------------
6.b. WAP in ALP to subtract two 16 bit numbers
data segment
no1 dw 19h
no2 dw 16H
result dw ?
data ends
code segment
assume ds:data, cs:code
start: mov ax,data
mov ds,ax
mov ax,no1
sub ax,no2
mov result,ax
int 03h
code ends
end start
output:
= File Edit View Run Breakpoints Data Options Window Help READY
+-[¦]-CPU 80486---------------------------------------1-[?][?]-+¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#start: start: mov ax,data ¦ ax 0003 ¦c=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0000 B8645C mov ax,5C64 ¦ bx 0000 ¦z=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#10: mov ds,ax ¦ cx 0000 ¦s=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0003 8ED8 mov ds,ax ¦ dx 0000 ¦o=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#11: mov ax,no1 ¦ si 0000 ¦p=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0005 A10000 mov ax,[#sub#no1]¦ di 0000 ¦a=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#12: sub ax,no2 ¦ bp 0000 ¦i=1¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0008 2B060200 sub ax,[#sub#no2]¦ sp 0000 ¦d=0¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#13: mov result,ax ¦ ds 5C64 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:000C?A30400 mov [#sub#result]¦ es 5C54 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦#sub#14: int 03h ¦ ss 5C64 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:000F CC int 03 ¦ cs 5C65 ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ cs:0010 FB sti ¦ ip 000C ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦---------------------------------------------¦ ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0000 19 00 16 00 00 00 00 00 ? ? ? ¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0008 00 00 00 00 00 00 00 00 ¦----------------¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0010 B8 64 5C 8E D8 A1 00 00 +d\Ä+í ¦ ss:0002 0016 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦ ds:0018 2B 06 02 00 A3 04 00 CC +?? ú? ¦ ? ss:0000?0019 ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
-----------------------------------------------------------------------------------------------
6. WAP in ALP to add and subtract two 16-bit numbers
------------------------------------------------------------------------------------------------------
7. WAP to implement Paging
import java.io.*;
class paging
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,p,off;
String page1,offset1,dir1,pdbr;
String addr=new String();
String dir=new String();
String page=new String();
String offset=new String();
int phy[]=new int[32];
System.out.println("enter the 32 bit linear address");
addr=br.readLine();
String append12="000000000000";
String append20="00000000000000000000";
String append22="0000000000000000000000";
String pdbr1="10101010101101010101";
pdbr=append12+pdbr1;
System.out.println("pdbr : "+pdbr);
dir1=addr.substring(0,10);
dir=append22+dir1;
System.out.println("Directory : "+dir);
page1=addr.substring(10,20);
page=append22+page1;
System.out.println("Page : "+page);
offset1=addr.substring(20,32);
offset=append20+offset1;
System.out.println("Offset : "+offset);
for(i=0;i<32;i++)
{
if(dir.charAt(i)==pdbr.charAt(i))
phy[i]=0;
else
phy[i]=1;
}
for(i=0;i<32;i++)
{
Character a=new Character(page.charAt(i));
String b=a.toString();
p=Integer.parseInt(b);
if(phy[i]==p)
phy[i]=0;
else
phy[i]=1;
}
for(i=0;i<32;i++)
{
Character a=new Character(offset.charAt(i));
String b=a.toString();
off=Integer.parseInt(b);
if(phy[i]==off)
phy[i]=0;
else
phy[i]=1;
}
System.out.println("physical address");
for(i=0;i<32;i++)
{
System.out.print(phy[i]);
}
}
}
/*
enter the 32 bit linear address
11100011010101011100101100011001
pdbr : 00000000000010101010101101010101
Directory : 00000000000000000000001110001101
Page : 00000000000000000000000101011100
Offset : 00000000000000000000101100011001
physical address
00000000000010101010001010011101
Process completed.
*/
-----------------------------------------------------------------------------------------------------
8. WAP to implement Segmentation
import java.io.*;
class segment_ins
{
static int c[]=new int[32];
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
String selector,index,offset;
int i;
System.out.println("enter the logical address");
String addr=in.readLine();
String gdt="00111100111100001111111100000000";
String ldt="11110000110011000000111100110011";
selector=addr.substring(0,16);
offset=addr.substring(16,48);
System.out.println("selector : "+selector);
System.out.println("offset : "+offset);
index=selector.substring(0,13);
String append16="0000000000000000";
index=index+"000";//mult by 8
index=append16+index;
if(selector.charAt(13)=='0')
{
add(index,gdt);
}
else
{
add(index,ldt);
}
String inter=new String();
for(i=0;i<32;i++)
{
inter=inter+c[i];
}
System.out.println("inter : "+inter);
add(inter,offset);
System.out.println("linear addr : ");
for(i=0;i<32;i++)
{
System.out.print(c[i]);
}
}
static void add(String index,String base)
{
int i,a,b;
for(i=0;i<32;i++)
{
c[i]=0;
}
System.out.println("index : "+index);
System.out.println("base : "+base);
for(i=31;i>=0;i--)
{
Character s=new Character(index.charAt(i));
String t=s.toString();
a=Integer.parseInt(t);
Character u=new Character(base.charAt(i));
String v=u.toString();
b=Integer.parseInt(v);
System.out.println(a+" "+b+" "+c[i]);
if(a+b+c[i]==3)
{
if(i!=0)
c[i-1]=1;
c[i]=1;
}
else if(a+b+c[i]==2)
{
if(i!=0)
c[i-1]=1;
c[i]=0;
}
else
{
c[i]=a+b+c[i];
}
}
}
}
/*
--------------------Configuration: <Default>--------------------
enter the logical address
101010100101010101100101110100010001001000101100
selector : 1010101001010101
offset : 01100101110100010001001000101100
index : 00000000000000001010101001010000
base : 11110000110011000000111100110011
0 1 0
0 1 0
0 0 0
0 0 0
1 1 0
0 1 1
1 0 1
0 0 1
0 1 0
1 1 0
0 1 1
1 1 1
0 0 1
1 0 0
0 0 0
1 0 0
0 0 0
0 0 0
0 1 0
0 1 0
0 0 0
0 0 0
0 1 0
0 1 0
0 0 0
0 0 0
0 0 0
0 0 0
0 1 0
0 1 0
0 1 0
0 1 0
inter : 11110000110011001011100110000011
index : 11110000110011001011100110000011
base : 01100101110100010001001000101100
1 0 0
1 0 0
0 1 0
0 1 0
0 0 0
0 1 0
0 0 0
1 0 0
1 0 0
0 1 0
0 0 0
1 0 0
1 1 0
1 0 1
0 0 1
1 0 0
0 1 0
0 0 0
1 0 0
1 0 0
0 1 0
0 0 0
1 1 0
1 1 1
0 1 1
0 0 1
0 1 0
0 0 0
1 0 0
1 1 0
1 1 1
1 0 1
linear addr :
01010110100111011100101110101111
Process completed.
*/
--------------------------------------------------------------------------------
9. WAP in ALP to reverse an array of numbers
data segment
strg db 01h, 06h, 05h, 08h, 02h, 03h, 04h, 07h, 0Ah, 02h;
rev db?
data ends
code segment
assume: cs:code, ds:data
start: mov ax,data
mov ds, ax
lea si,strg
lea di,rev
mov ch,0Ah
mov cl,0Ah
up: inc si
dec ch
JNZ up
up1: mov ah,[si]
mov[di],ah
inc di
des si
dec cl
JNZ up1
int 03h
code ends
end start
File Edit View Run Breakpoints Data Options Window Help READY
╔═[■]═CPU 80486═══════════════════════════════Ð═══════1═[↑][↓]═╗░░░░░░░░░░░░░░░░
║#reverse#25: int 03h │ ax 06BC │c=0║░░░░░░░░░░░░░░░░
║ cs:001E CC int 03 │ bx 0000 │z=1║░░░░░░░░░░░░░░░░
║ cs:001F►00FB add bl,bh │ cx 0000 │s=0║░░░░░░░░░░░░░░░░
║ cs:0021 52 push dx │ dx 0000 │o=0║░░░░░░░░░░░░░░░░
║ cs:0022 0902 or [bp+si],ax │ si 0000 │p=1║░░░░░░░░░░░░░░░░
║ cs:0024 3200 xor al,[bx+si] │ di 0014 │a=0║░░░░░░░░░░░░░░░░
║ cs:0026 0000 add [bx+si],al │ bp 0000 │i=1║░░░░░░░░░░░░░░░░
║ cs:0028 07 pop es │ sp 0000 │d=0║░░░░░░░░░░░░░░░░
║ cs:0029 001E0000 add [#reverse#str│ ds 5EBC │ ║░░░░░░░░░░░░░░░░
║ cs:002D 0005 add [di],al │ es 5EAC │ ║░░░░░░░░░░░░░░░░
║ cs:002F 0000 add [bx+si],al │ ss 5EBC │ ║░░░░░░░░░░░░░░░░
║ cs:0031 0001 add [bx+di],al │ cs 5EBD │ ║░░░░░░░░░░░░░░░░
║ cs:0033 0000 add [bx+si],al │ ip 001F │ ║░░░░░░░░░░░░░░░░
Ã─────────────────────────────────────────────┤ │ ║░░░░░░░░░░░░░░░░
║ ds:0000 01 06 05 08 02 03 04 07 ☺♠♣◘☻♥♦• ▲ │ ║░░░░░░░░░░░░░░░░
║ ds:0008 0A 02 00 02 0A 07 04 03 ◙☻ ☻◙•♦♥ ■────────────┴───Â░░░░░░░░░░░░░░░░
║ ds:0010 02 08 05 06 D8 BE 00 00 ☻◘♣♠Ï¥ ▒ ss:0002 0805 ║░░░░░░░░░░░░░░░░
║ ds:0018 BF 0A 00 B5 0A B1 0A 46 ┐◙ Á◙▒◙F ▼ ss:0000►0601 ║░░░░░░░░░░░░░░░░
╚◄■▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒►¤═══════════════─┘░░░░░░░░░░░
import java.io.*;
class paging
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,p,off;
String page1,offset1,dir1,pdbr;
String addr=new String();
String dir=new String();
String page=new String();
String offset=new String();
int phy[]=new int[32];
System.out.println("enter the 32 bit linear address");
addr=br.readLine();
String append12="000000000000";
String append20="00000000000000000000";
String append22="0000000000000000000000";
String pdbr1="10101010101101010101";
pdbr=append12+pdbr1;
System.out.println("pdbr : "+pdbr);
dir1=addr.substring(0,10);
dir=append22+dir1;
System.out.println("Directory : "+dir);
page1=addr.substring(10,20);
page=append22+page1;
System.out.println("Page : "+page);
offset1=addr.substring(20,32);
offset=append20+offset1;
System.out.println("Offset : "+offset);
for(i=0;i<32;i++)
{
if(dir.charAt(i)==pdbr.charAt(i))
phy[i]=0;
else
phy[i]=1;
}
for(i=0;i<32;i++)
{
Character a=new Character(page.charAt(i));
String b=a.toString();
p=Integer.parseInt(b);
if(phy[i]==p)
phy[i]=0;
else
phy[i]=1;
}
for(i=0;i<32;i++)
{
Character a=new Character(offset.charAt(i));
String b=a.toString();
off=Integer.parseInt(b);
if(phy[i]==off)
phy[i]=0;
else
phy[i]=1;
}
System.out.println("physical address");
for(i=0;i<32;i++)
{
System.out.print(phy[i]);
}
}
}
/*
enter the 32 bit linear address
11100011010101011100101100011001
pdbr : 00000000000010101010101101010101
Directory : 00000000000000000000001110001101
Page : 00000000000000000000000101011100
Offset : 00000000000000000000101100011001
physical address
00000000000010101010001010011101
Process completed.
*/
-----------------------------------------------------------------------------------------------------
8. WAP to implement Segmentation
import java.io.*;
class segment_ins
{
static int c[]=new int[32];
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
String selector,index,offset;
int i;
System.out.println("enter the logical address");
String addr=in.readLine();
String gdt="00111100111100001111111100000000";
String ldt="11110000110011000000111100110011";
selector=addr.substring(0,16);
offset=addr.substring(16,48);
System.out.println("selector : "+selector);
System.out.println("offset : "+offset);
index=selector.substring(0,13);
String append16="0000000000000000";
index=index+"000";//mult by 8
index=append16+index;
if(selector.charAt(13)=='0')
{
add(index,gdt);
}
else
{
add(index,ldt);
}
String inter=new String();
for(i=0;i<32;i++)
{
inter=inter+c[i];
}
System.out.println("inter : "+inter);
add(inter,offset);
System.out.println("linear addr : ");
for(i=0;i<32;i++)
{
System.out.print(c[i]);
}
}
static void add(String index,String base)
{
int i,a,b;
for(i=0;i<32;i++)
{
c[i]=0;
}
System.out.println("index : "+index);
System.out.println("base : "+base);
for(i=31;i>=0;i--)
{
Character s=new Character(index.charAt(i));
String t=s.toString();
a=Integer.parseInt(t);
Character u=new Character(base.charAt(i));
String v=u.toString();
b=Integer.parseInt(v);
System.out.println(a+" "+b+" "+c[i]);
if(a+b+c[i]==3)
{
if(i!=0)
c[i-1]=1;
c[i]=1;
}
else if(a+b+c[i]==2)
{
if(i!=0)
c[i-1]=1;
c[i]=0;
}
else
{
c[i]=a+b+c[i];
}
}
}
}
/*
--------------------Configuration: <Default>--------------------
enter the logical address
101010100101010101100101110100010001001000101100
selector : 1010101001010101
offset : 01100101110100010001001000101100
index : 00000000000000001010101001010000
base : 11110000110011000000111100110011
0 1 0
0 1 0
0 0 0
0 0 0
1 1 0
0 1 1
1 0 1
0 0 1
0 1 0
1 1 0
0 1 1
1 1 1
0 0 1
1 0 0
0 0 0
1 0 0
0 0 0
0 0 0
0 1 0
0 1 0
0 0 0
0 0 0
0 1 0
0 1 0
0 0 0
0 0 0
0 0 0
0 0 0
0 1 0
0 1 0
0 1 0
0 1 0
inter : 11110000110011001011100110000011
index : 11110000110011001011100110000011
base : 01100101110100010001001000101100
1 0 0
1 0 0
0 1 0
0 1 0
0 0 0
0 1 0
0 0 0
1 0 0
1 0 0
0 1 0
0 0 0
1 0 0
1 1 0
1 0 1
0 0 1
1 0 0
0 1 0
0 0 0
1 0 0
1 0 0
0 1 0
0 0 0
1 1 0
1 1 1
0 1 1
0 0 1
0 1 0
0 0 0
1 0 0
1 1 0
1 1 1
1 0 1
linear addr :
01010110100111011100101110101111
Process completed.
*/
--------------------------------------------------------------------------------
9. WAP in ALP to reverse an array of numbers
data segment
strg db 01h, 06h, 05h, 08h, 02h, 03h, 04h, 07h, 0Ah, 02h;
rev db?
data ends
code segment
assume: cs:code, ds:data
start: mov ax,data
mov ds, ax
lea si,strg
lea di,rev
mov ch,0Ah
mov cl,0Ah
up: inc si
dec ch
JNZ up
up1: mov ah,[si]
mov[di],ah
inc di
des si
dec cl
JNZ up1
int 03h
code ends
end start
File Edit View Run Breakpoints Data Options Window Help READY
╔═[■]═CPU 80486═══════════════════════════════Ð═══════1═[↑][↓]═╗░░░░░░░░░░░░░░░░
║#reverse#25: int 03h │ ax 06BC │c=0║░░░░░░░░░░░░░░░░
║ cs:001E CC int 03 │ bx 0000 │z=1║░░░░░░░░░░░░░░░░
║ cs:001F►00FB add bl,bh │ cx 0000 │s=0║░░░░░░░░░░░░░░░░
║ cs:0021 52 push dx │ dx 0000 │o=0║░░░░░░░░░░░░░░░░
║ cs:0022 0902 or [bp+si],ax │ si 0000 │p=1║░░░░░░░░░░░░░░░░
║ cs:0024 3200 xor al,[bx+si] │ di 0014 │a=0║░░░░░░░░░░░░░░░░
║ cs:0026 0000 add [bx+si],al │ bp 0000 │i=1║░░░░░░░░░░░░░░░░
║ cs:0028 07 pop es │ sp 0000 │d=0║░░░░░░░░░░░░░░░░
║ cs:0029 001E0000 add [#reverse#str│ ds 5EBC │ ║░░░░░░░░░░░░░░░░
║ cs:002D 0005 add [di],al │ es 5EAC │ ║░░░░░░░░░░░░░░░░
║ cs:002F 0000 add [bx+si],al │ ss 5EBC │ ║░░░░░░░░░░░░░░░░
║ cs:0031 0001 add [bx+di],al │ cs 5EBD │ ║░░░░░░░░░░░░░░░░
║ cs:0033 0000 add [bx+si],al │ ip 001F │ ║░░░░░░░░░░░░░░░░
Ã─────────────────────────────────────────────┤ │ ║░░░░░░░░░░░░░░░░
║ ds:0000 01 06 05 08 02 03 04 07 ☺♠♣◘☻♥♦• ▲ │ ║░░░░░░░░░░░░░░░░
║ ds:0008 0A 02 00 02 0A 07 04 03 ◙☻ ☻◙•♦♥ ■────────────┴───Â░░░░░░░░░░░░░░░░
║ ds:0010 02 08 05 06 D8 BE 00 00 ☻◘♣♠Ï¥ ▒ ss:0002 0805 ║░░░░░░░░░░░░░░░░
║ ds:0018 BF 0A 00 B5 0A B1 0A 46 ┐◙ Á◙▒◙F ▼ ss:0000►0601 ║░░░░░░░░░░░░░░░░
╚◄■▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒►¤═══════════════─┘░░░░░░░░░░░
--------------------------------------------------------------------------------------
import java.io.*;
import java.sql.*;
class BPL
{
static String
his[]={"strongly_taken","weakly_taken","weakly_nottaken","strongly_nottaken"};
public static void main(String args[])throws IOException
{
String
his[]={"strongly_taken","weakly_taken","weakly_nottaken","strongly_nottaken"};
String btb[][]=new String[10][3];
boolean flag=true;
int t=0;
String ins="";int i=0,j;
DataInputStream in=new DataInputStream(System.in);
int k=0;
for(k=0;k<10;k++)
{
System.out.println("Enter the instruction or q to
exit");
ins=in.readLine();
if(ins.equalsIgnoreCase("q"))
System.exit(0);
else
for(i=0;i<10;i++)
if(ins.equalsIgnoreCase(btb[i][1]))
{
flag=true;
break;
}
else
flag=false;
if(flag==true)
{
System.out.println("Instruction is present");
System.out.println("Branch
Prediction:"+btb[i][2]);
System.out.println("D1 execution stage branch
taken:0 not taken:1");
t=Integer.parseInt(in.readLine());
if(t==0)
{
btb[i][0]="1";
for(j=0;j<4;j++)
{
if(btb[i][2].equalsIgnoreCase(his[i]))
{
if(j==0)
btb[i][2]=his[j];
else
btb[i][2]=his[j-1];
}
}
}
else
{
for(j=0;j<4;j++)
{
if(btb[i][2].equalsIgnoreCase(his[j]))
{
if(j==3)
{btb[i][2]=his[j];break;}
else
{btb[i][2]=his[j+1];break;}
}
}
}
System.out.println("Updataed history bit of
:"+btb[i][1]+" to "+btb[i][2]);
}
else
{
i=k;
System.out.println("Instruction is not
present");
System.out.println("Brach prediction not
taken");
System.out.println("D1 execution stage branch
taken:0 not taken:1");
t=Integer.parseInt(in.readLine());
if(t==0)
{
btb[i][1]=ins;
btb[i][2]=his[0];
btb[i][0]="1";
}
}
}
}
}
/*output:
Enter the
instruction or q to exit
jc
Instruction is not present
Brach prediction not taken
D1 execution stage branch taken:0 not taken:1
1
Enter the instruction or q to exit
jc
Instruction is not present
Brach prediction not taken
D1 execution stage branch taken:0 not taken:1
1
Enter the instruction or q to exit
jp
Instruction is not present
Brach prediction not taken
D1 execution stage branch taken:0 not taken:1
0
Enter the instruction or q to exit
jc
Instruction is not present
Brach prediction not taken
D1 execution stage branch taken:0 not taken:1
1
Enter the instruction or q to exit
q
*/
---------------------------------------------------------------------------------------
11. WAP to implement Data Cache
import java.util.*;
class DataCache
{
public static void main(String args[]) throws Exception
{
Scanner s = new Scanner(System.in);
int dc[] = new int[32];
int i =0;
int x = 1;
int y = 1;
try
{
System.out.println("Enter the bit values:");
for(i=0;i<=31;i++)
{
System.out.println("BIT " + i);
dc[i] = s.nextInt();
}
}
catch(Exception e)
{
}
int a[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,};
int b[]={0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,};
if((a[0]!=0)||(a[1]!=0))
{
x= check(dc,a);
}
if((b[0]!=0)||(b[1]!=0))
{
y = check(dc,b);
}
System.out.println("Line Address: ");
for(i=5;i<=11;i++)
System.out.print(dc[i]);
if((x==0)||(y==0))
{
System.out.println();
System.out.println("Cache Hit Memory Address:");
for(i=12;i<=31;i++)
System.out.print(dc[i]);
}
else
{
System.out.println("Cache Miss");
}
}
public static int check(int dc[],int ab[])
{
int k = 0;
int i = 0;
for(i=12;i<=31;i++)
{
if(dc[i]!=ab[i])
{
return(1);
}
}
return(0);
}
}
/*Output:
Enter the bit values:
BIT 0
1
BIT 1
1
BIT 2
1
BIT 3
1
BIT 4
1
BIT 5
1
BIT 6
1
BIT 7
1
BIT 8
1
BIT 9
1
BIT 10
1
BIT 11
1
BIT 12
1
BIT 13
1
BIT 14
1
BIT 15
1
BIT 16
1
BIT 17
1
BIT 18
1
BIT 19
1
BIT 20
1
BIT 21
1
BIT 22
1
BIT 23
1
BIT 24
1
BIT 25
1
BIT 26
1
BIT 27
1
BIT 28
1
BIT 29
1
BIT 30
1
BIT 31
1
Line Address:
1111111
Cache Hit Memory Address:
11111111111111111111
Process completed.
*/
import java.util.*;
class DataCache
{
public static void main(String args[]) throws Exception
{
Scanner s = new Scanner(System.in);
int dc[] = new int[32];
int i =0;
int x = 1;
int y = 1;
try
{
System.out.println("Enter the bit values:");
for(i=0;i<=31;i++)
{
System.out.println("BIT " + i);
dc[i] = s.nextInt();
}
}
catch(Exception e)
{
}
int a[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,};
int b[]={0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,};
if((a[0]!=0)||(a[1]!=0))
{
x= check(dc,a);
}
if((b[0]!=0)||(b[1]!=0))
{
y = check(dc,b);
}
System.out.println("Line Address: ");
for(i=5;i<=11;i++)
System.out.print(dc[i]);
if((x==0)||(y==0))
{
System.out.println();
System.out.println("Cache Hit Memory Address:");
for(i=12;i<=31;i++)
System.out.print(dc[i]);
}
else
{
System.out.println("Cache Miss");
}
}
public static int check(int dc[],int ab[])
{
int k = 0;
int i = 0;
for(i=12;i<=31;i++)
{
if(dc[i]!=ab[i])
{
return(1);
}
}
return(0);
}
}
/*Output:
Enter the bit values:
BIT 0
1
BIT 1
1
BIT 2
1
BIT 3
1
BIT 4
1
BIT 5
1
BIT 6
1
BIT 7
1
BIT 8
1
BIT 9
1
BIT 10
1
BIT 11
1
BIT 12
1
BIT 13
1
BIT 14
1
BIT 15
1
BIT 16
1
BIT 17
1
BIT 18
1
BIT 19
1
BIT 20
1
BIT 21
1
BIT 22
1
BIT 23
1
BIT 24
1
BIT 25
1
BIT 26
1
BIT 27
1
BIT 28
1
BIT 29
1
BIT 30
1
BIT 31
1
Line Address:
1111111
Cache Hit Memory Address:
11111111111111111111
Process completed.
*/
-------------------------------------------------------------------------------------