- Get link
- X
- Other Apps
Group A
Assignment No:1.1
Assignment No:Write ALP to print Hello World!Program using
32 model and segmentation
hello db 'hello
world$',0ah
charactor:
len equ $-hello
section .text
global _start:
_start:
mov eax,4
mov ebx,1
mov ecx,hello
mov edx,len
int 80h
mov eax,1
mov ebx,0
int 80h
OUTPUT
ell-152@ell152-OptiPlex-390:~$
cd Desktop
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 hello34.asm -o hello34.o
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o hello34 hello34.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./hello34
hello world$
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No:1.2
Assignment Name:Write ALP to print “Hello
World!” Program using 64 model and segmentation
section .data:
hello db 'hello
world',10
character:
len equ $-hello
section .text
global _start:
_start:
mov rax,4
mov rbx,1
mov rcx,hello
mov rdx,len
int 80h
mov rax,1
mov rbx,0
int 80h
OUTPUT
ell-152@ell152-OptiPlex-390:~$
cd Desktop
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 hello64.asm -o hello64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o hello64 hello64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./hello64
hello world
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No:2.2
Aim: Write an ALP to accept ten 32-bit
and 64 bit Hexadecimal numbers from user and store then in data segment table
and display then numbers.
section .data
msg1 db 'ALP to accept ten 32-bit and 64 bit Hexadecimal numbers from
user and store then in data segment table and display then numbers ',10
msg1len equ $-msg1
msg2 db 'enter the 10 64
bit nos',10
msg2len equ $-msg2
msg3 db 'display
num:',10
msg3len equ $-msg3
section .bss
num resq 30
section .text
global _start
_start:
mov
rax,4
mov
rbx,1
mov
rcx,msg1
mov
rdx,msg1len
int
80h
mov
rax,4
mov
rbx,1
mov
rcx,msg2
mov
rdx,msg2len
int
80h
mov rsi,num
mov rdi,30
L1:
mov rax,3
mov
rbx,0
mov
rcx,rsi
mov
rdx,8
int
80h
add rsi,8
dec rdi
jnz L1
mov rax,4
mov
rbx,1
mov
rcx,msg3
mov
rdx,msg3len
int
80h
mov
rsi,num
mov
rdi,30
L3:
mov rax,4
mov
rbx,1
mov
rcx,rsi
mov
rdx,8
int
80h
add rsi,8
dec rdi
jnz L3
int 80h
mov
rax,1
mov
rbx,0
int 80h
OUTPUT
ALP to accept ten 32-bit and 64 bit
Hexadecimal numbers from user and store then in data segment table and display
then numbers
enter the 10 64 bit nos
1236547891236547
1526369542125633
6856235168965566
9894623541546215
9784654655655666
9865232345635465
6546512566596565
4565521654563566
8545465465465444
5415365451536575
display num:
1236547891236547
1526369542125633
6856235168965566
9894623541546215
9784654655655666
9865232345635465
6546512566596565
4565521654563566
8545465465465444
5415365451536575
Assignment No:03
Aim:Write an ALP to accept a string and to display it’s length.
section .data:
msg1 db 'enter
string:',10
msg1len equ $-msg1
msg2 db 'string is:',10
msg2len equ $-msg2
msg3 db 'length of
string is:',10
msg3len equ $-msg3
msg4 db 'thank you',10
msg4len equ $-msg4
section .bss
dispnum resb 8
count resd 1
buffer resb 40
bufferlen:equ $-buffer
section .text
global _start:
_start:
mov eax,4
mov ebx,1
mov ecx,msg1
mov edx,msg1len
int 80h
mov eax,3
mov ebx,0
mov ecx,buffer
mov edx,count
int 80h
mov[count],eax
mov eax,4
mov ebx,1
mov ecx,msg2
mov edx,msg2len
int 80h
mov eax,4
mov ebx,1
mov ecx,buffer
mov edx,count
int 80h
mov eax,4
mov ebx,1
mov ecx,msg3
mov edx,msg3len
int 80h
mov esi,dispnum+7
mov eax,[count]
mov ecx,8
dec eax
L1:
mov edx,0
mov ebx,10
div ebx
add dl,30h
mov[esi],dl
dec esi
dec ecx
jnz L1
mov eax,4
mov ebx,1
mov ecx,dispnum
mov edx,8
int 80h
mov eax,4
mov ebx,1
mov ecx,msg4
mov edx,msg4len
int 80h
mov eax,1
mov ebx,0
int 80h
OUTPUT
ell-152@ell152-OptiPlex-390:~$
cd Desktop
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 ass2.o -o ass2
nasm: fatal: unable to
open input file `ass2.o'
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 ass2.asm -o ass2.o
nasm: fatal: unable to
open input file `ass2.asm'
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 strg2.asm -o strg2.o
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o strg2 strg2.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./strg2
enter string:
ameya
string is:
ameya
length of string is:
00000005
thank you
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No : 4.1
Aim : Write an ALP to perform arithmetic and logical operation using,
32-bit and 64-bit numbers stored in an array using 64 bit register operations.
section
.data
nline db 10,10
nline_len: equ $-nline
arr64 dq
0000000000112233H, 00112233H, 00112233H, 00112233H, 00112233H
n: equ 5
msg db 10,10,"The
sum of 64-bit array elements (without carry) is : "
msg_len: equ $-msg
Section .bss
sum resq
1
char_sum resb 16 ;you
can change the macros as per 64-bit convensions
%macro
print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
exit 0
mov eax, 1
mov ebx, 0
int 80h
%endmacro
; If U ARE MODIFYING 32-BIT PROGRAM then
; Check line by line and make all 'e' as 'r' and other modifications
; for 64-bit numbers
section
.text
global _start
_start:
mov rsi, arr64
mov rdi, n
mov rax, 0
;sum register
next_num:
add rax,[rsi]
add
rsi,8
; 64 bit nos i.e. 8 bytes
dec
rdi
jnz
next_num
mov [sum], rax ;
store sum
print msg, msg_len
mov
rax,[sum] ; load value
of sum in rax
call
disp64_proc ; display
sum
print nline, nline_len
exit
disp64_proc:
mov
rsi,char_sum+15 ; load
last byte address of char_sum buffer in rsi
mov
rcx,16
; number of digits
cnt:
mov rdx,0
; make rdx=0 (as in div instruction rdx:rax/rbx)
mov
rbx,16
; divisor=16 for hex
div
rbx
cmp
dl, 09h
; check for remainder in RDX
jbe
add30
add
dl, 07h
add30:
add
dl,30h
; calculate ASCII code
mov
[rsi],dl ; store it in
buffer
dec
rsi
; point to one byte back
dec
rcx
; decrement count
jnz
cnt
; if not zero repeat
print
char_sum,16 ; display result on screen
ret
OUTPUT
The sum of 64-bit array
elements (without carry) is : 000000000055AAFF
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No : 4.5
Aim : Write an ALP to perform arithmetic and logical
operation using, 32-bit and 64-bit numbers stored in an array using 64 bit
register operations.
section
.data
nline db 10,10
nline_len: equ $-nline
arr64 dq
0000000055555555H, 11111111H, 11111111H, 11111111H, 11111111H
n: equ 5
msg db 10,10,"The
result of AND operation on 64-bit array elements is : "
msg_len: equ $-msg
Section .bss
ans resq
1
char_ans resb 16 ;you
can change the macros as per 64-bit convensions
%macro
print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
exit 0
mov eax, 1
mov ebx, 0
int 80h
%endmacro
; If U ARE MODIFYING 32-BIT PROGRAM then
; Check line by line and make all 'e' as 'r' and other
modifications
; for 64-bit numbers
section
.text
global
_start
_start:
mov rsi, arr64
mov rdi, n
mov rax, [rsi]
; load 1st no.
add
rsi,8
; point to 2nd element
dec
rdi
; n=n-1
next_num:
and rax,[rsi]
add
rsi,8
; 64 bit nos i.e. 8 bytes
dec
rdi
jnz next_num
mov [ans], rax ; store
ans
print msg, msg_len
mov
rax,[ans] ; load value
of ans in rax
call
disp64_proc ; display
ans
print
nline, nline_len
exit
disp64_proc:
mov
rsi,char_ans+15 ; load
last byte address of char_ans buffer in rsi
mov
rcx,16
; number of digits
cnt:
mov rdx,0
; make rdx=0 (as in div instruction rdx:rax/rbx)
mov
rbx,16
; divisor=16 for hex
div
rbx
cmp
dl, 09h
; check for remainder in RDX
jbe add30
add dl, 07h
add30:
add
dl,30h
; calculate ASCII code
mov
[rsi],dl ; store it in
buffer
dec
rsi
; point to one byte back
dec
rcx
; decrement count
jnz
cnt
; if not zero repeat
print
char_ans,16 ; display result on screen
ret
OUTPUT
ell-152@ell152-OptiPlex-390:~/Desktop$
cd Desktop
bash: cd: Desktop: No
such file or directory
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 and64.asm -o and64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o and64 and64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./and64
The result of AND
operation on 64-bit array elements is : 0000000011111111
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No:4.4
Aim:Write an ALP to perform arithmetic and logical operations
using ‘n’, 32-bit and 64-bit numbers stored in an array using 64 bit register
operations.
section
.data
nline db 10,10
nline_len: equ $-nline
arr64 dq
0000000055555555H, 11111111H, 11111111H, 11111111H, 11111111H
n: equ 5
msg db 10,10,"The
result of OR operation on 64-bit array elements is : "
msg_len: equ $-msg
Section .bss
ans resq
1
char_ans resb 16 ;you can change the macros as per 64-bit convensions
%macro
print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
exit 0
mov eax, 1
mov ebx, 0
int 80h
%endmacro
; If U ARE MODIFYING 32-BIT PROGRAM then
; Check line by line and make all 'e' as 'r' and other modifications
; for 64-bit numbers
section
.text
global _start
_start:
mov rsi, arr64
mov rdi, n
mov rax, [rsi]
; load 1st no.
add
rsi,8
; point to 2nd element
dec
rdi ;
n=n-1
next_num:
or rax,[rsi]
add
rsi,8
; 64 bit nos i.e. 8 bytes
dec
rdi
jnz next_num
mov [ans], rax ; store
ans
print msg, msg_len
mov
rax,[ans] ; load value
of ans in rax
call
disp64_proc ; display
ans
print nline, nline_len
exit
disp64_proc:
mov
rsi,char_ans+15 ; load
last byte address of char_ans buffer in rsi
mov
rcx,16
; number of digits
cnt:
mov rdx,0
; make rdx=0 (as in div instruction rdx:rax/rbx)
mov
rbx,16
; divisor=16 for hex
div
rbx
cmp
dl, 09h
; check for remainder in RDX
jbe add30
add dl, 07h
add30:
add
dl,30h
; calculate ASCII code
mov
[rsi],dl ; store it in
buffer
dec
rsi
; point to one byte back
dec
rcx
; decrement count
jnz
cnt
; if not zero repeat
print
char_ans,16 ; display result on screen
ret
OUTPUT
ell-152@ell152-OptiPlex-390:~$
cd Desktop
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 or64.asm -o or64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o or64 pr64.o
ld: cannot find pr64.o:
No such file or directory
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o or64 or64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./or64
The result of OR
operation on 64-bit array elements is : 0000000055555555
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No:4.3
Aim:Write an ALP to perform arithmetic and logical operations
using ‘n’, 32-bit and 64-bit number stored in an array using 64 bit register
operations.
section
.data
nline db 10,10
nline_len: equ $-nline
arr64 dq
0000000055555555H, 11111111H, 11111111H, 11111111H, 11111111H
n: equ 5
msg db 10,10,"The
subtraction of 64-bit array elements is : "
msg_len: equ $-msg
Section .bss
ans resq
1
char_ans resb 16 ;you can change the macros as per 64-bit convensions
%macro
print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
exit 0
mov eax, 1
mov ebx, 0
int 80h
%endmacro
; If U ARE MODIFYING 32-BIT PROGRAM then
; Check line by line and make all 'e' as 'r' and other
modifications
; for 64-bit numbers
section
.text
global _start
_start:
mov rsi, arr64
mov rdi, n
mov rax, [rsi]
; load 1st no.
add
rsi,8
; point to 2nd element
dec
rdi
; n=n-1
next_num:
sub rax,[rsi]
add
rsi,8
; 64 bit nos i.e. 8 bytes
dec
rdi
jnz next_num
mov [ans], rax ; store
sub
print msg, msg_len
mov
rax,[ans] ; load value
of sub in rax
call
disp64_proc ; display
ans
print nline, nline_len
exit
disp64_proc:
mov
rsi,char_ans+15 ; load
last byte address of char_ans buffer in rsi
mov
rcx,16
; number of digits
cnt:
mov rdx,0
; make rdx=0 (as in div instruction rdx:rax/rbx)
mov
rbx,16
; divisor=16 for hex
div
rbx
cmp
dl, 09h
; check for remainder in RDX
jbe add30
add dl, 07h
add30:
add
dl,30h
; calculate ASCII code
mov
[rsi],dl ; store it in
buffer
dec
rsi
; point to one byte back
dec
rcx
; decrement count
jnz
cnt
; if not zero repeat
print
char_ans,16 ; display result on screen
ret
OUTPUT
ell-152@ell152-OptiPlex-390:~$
cd Desktop
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 sub64.asm -o sub64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o sub64 sub64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./sub64
The subtraction of
64-bit array elements is : 0000000011111111
ell-152@ell152-OptiPlex-390:~/Desktop$
Group A
Assignment No:4.2
Aim:Write an ALP to perform arithmetic and logical operations
using ‘n’, 32-bit and 64-bit numbers stored in an array using 64 bit register
operations.
section
.data
nline db 10,10
nline_len: equ $-nline
arr64 dq 0000000055555555H,
11111111H, 11111111H, 11111111H, 11111111H
n: equ 5
msg db 10,10,"The
result of XOR operation on 64-bit array elements is : "
msg_len: equ $-msg
Section .bss
ans resq
1
char_ans
resb 16 ;you can
change the macros as per 64-bit convensions
%macro
print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
exit 0
mov eax, 1
mov ebx, 0
int 80h
%endmacro
; If U ARE MODIFYING 32-BIT PROGRAM then
; Check line by line and make all 'e' as 'r' and other
modifications
; for 64-bit numbers
section
.text
global _start
_start:
mov rsi, arr64
mov rdi, n
mov rax, [rsi]
; load 1st no.
add
rsi,8
; point to 2nd element
dec
rdi
; n=n-1
next_num:
xor rax,[rsi]
add
rsi,8
; 64 bit nos i.e. 8 bytes
dec
rdi
jnz next_num
mov [ans], rax ; store
ans
print msg, msg_len
mov
rax,[ans] ; load value
of ans in rax
call
disp64_proc ; display
ans
print nline, nline_len
exit
disp64_proc:
mov
rsi,char_ans+15 ; load
last byte address of char_ans buffer in rsi
mov
rcx,16
; number of digits
cnt:
mov rdx,0
; make rdx=0 (as in div instruction rdx:rax/rbx)
mov
rbx,16
; divisor=16 for hex
div
rbx
cmp
dl, 09h
; check for remainder in RDX
jbe add30
add dl, 07h
add30:
add
dl,30h
; calculate ASCII code
mov
[rsi],dl ; store it in
buffer
dec
rsi
; point to one byte back
dec
rcx
; decrement count
jnz
cnt
; if not zero repeat
print
char_ans,16 ; display result on screen
ret
OUTPUT
ell-152@ell152-OptiPlex-390:~$
cd Desktop
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 xor64.asm -o xor64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o xor64 xor64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./xor64
The result of XOR
operation on 64-bit array elements is : 0000000055555555
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No:06
Aim:Write an ALP to program to use GDTR, LDTR and IDTR in Real
Mode.
section
.data
nline db 10,10
nline_len: equ $-nline
colon db
":"
rmsg
db 10,'To use
GDTR,LDTR,IDTR in Real mode'
rmsg_len: equ $-rmsg
Section .bss
GDTR resw
3 ; 48 bits, so 3 words
IDTR resw 3
LDTR resw
1 ; 16 bits, so 1 word
section
.text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, rmsg
mov edx, rmsg_len
int 80h
SMSW
[MSW]
SGDT
[GDTR] ;save GDTR
SIDT
[IDTR] ;save IDTR
SLDT
[LDTR] ;;save LDTR
mov eax, 1
mov ebx, 0
int 80h
Group B
Assignment No:01
Aim:Write an ALP to fond the largest of given
byte/Word/Dword/64-bit numbers
section .data
larg_msg db 'Largest Number is::'
larg_len: equ $-larg_msg
nwline db 10
array
dd 0fa100001h,0b2000002h,0ffffffffh,0d400004h, 0500005h
;array elements
arrcnt dd 05h
section .bss
dnum_buff resb 8
large
resd 1
%macro dispmsg 2
mov
eax,4 ;System call for write
mov
ebx,1 ;standard output stream
mov
ecx,%1 ;message start address
mov
edx,%2 ;message length
int
80h
%endmacro
section .text
global _start
global break
_start:
mov
esi,0
mov
ecx,[arrcnt]
break1:
mov eax,0
lup1:
cmp eax,[array+esi*4] ;Compare accumulator with array
element
ja
lskip1 ;If accumulator is greater go to skip
mov
eax,[array+esi*4] ;Else move array element in accumulator
lskip1:
inc esi ;Point to
next element
loop
lup1
mov
[large],eax
dispmsg larg_msg,larg_len
mov
ebx,[large]
call
disp_num
dispmsg nwline,1
exit:
mov eax,01
mov
ebx,0
int
80h
disp_num:
mov
edi,dnum_buff ;point esi to buffer
mov
ecx,8 ;load number of digits to display
dispup1:
rol
ebx,4 ;rotate number left by four bits
mov
dl,bl ;move lower byte in dl
and
dl,0fh ;mask upper digit of byte in dl
add
dl,30h ;add 30h to calculate ASCII code
cmp
dl,39h ;compare with 39h
jbe
dispskip1 ;if less than 39h akip adding 07
more
add
dl,07h ;else add 07
dispskip1:
mov
[edi],dl ;store ASCII code in buffer
inc
edi ;point to next byte
loop
dispup1 ;decrement the count of digits to
display
;if not zero
jump to repeat
dispmsg dnum_buff,8
ret
OUTPUT
;[mahendra@(none) alp]$
nasm -f elf64 msmalb01.asm
;[mahendra@(none) alp]$
ld -o msmalb01 msmalb01.o
;[mahendra@(none) alp]$
./msmalb01
;Largest Number
is::FFFFFFFF
;[mahendra@(none) alp]$
Assignment No:06
Aim:Write a switch case driven ALP to perform 64-bit hexadecimal
arithmetic operations (+,-,*, /) using suitable macros. Define procedure for
each operation.
section .data
nline db 10,10
nline_len: equ $-nline
no1 dq
0000000000112233H
no2 dq 0000000000112233H
menu db 10,"
-Menu- "
db 10,"1.
Addition"
db 10,"2.
Subtraction"
db 10,"3.
Multiplication"
db 10,"4.
Division"
db
10," Exit"
db 10,10,"
Enter Your Choice: "
menu_len: equ $-menu
amsg db
10,10,"Addition Result is : "
amsg_len: equ $-amsg
smsg db
10,10,"subtraction Result is : "
smsg_len: equ $-smsg
mmsg db 10,10,"multiplication
Result is : "
mmsg_len: equ $-mmsg
dmsg db
10,10,"Division Result is : "
dmsg_len: equ $-dmsg
emsg db
10,10,"Exit from the Pgogram....", 10,10
emsg_len: equ $-emsg
Section .bss
choice resb 2
choice_len: equ $-choice
ans resq
1
char_ans resb 16 ;you can change the macros as per 64-bit convensions
%macro
print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
read 2
mov eax, 3
mov ebx, 0
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
exit 0
mov eax, 1
mov ebx, 0
int 80h
%endmacro
; If U ARE MODIFYING 32-BIT PROGRAM then
; Check line by line and make all 'e' as 'r' and other
modifications
; for 64-bit numbers
section
.text
global _start
_start:
print menu, menu_len
read choice, choice_len
mov al,byte [choice]
case1:
CMP al,'1'
jne case2
call add64_proc
jmp _start
case2:
CMP al,'2'
jne case3
call sub64_proc
jmp _start
case3:
CMP al,'3'
jne case4
call mul64_proc
jmp _start
case4:
CMP al,'4'
jne caseexit
call div64_proc
jmp _start
caseexit:
print emsg,emsg_len
exit
add64_proc:
mov rax,[no1]
mov rbx,[no2]
add rax,rbx
mov [ans], rax ; store
ans
print amsg, amsg_len
mov
rax,[ans]
; load value of ans in rax
call
disp64_proc ; display
ans
print nline, nline_len
ret
sub64_proc:
mov rax,[no1]
mov rbx,[no2]
sub rax,rbx
mov [ans], rax ; store
ans
print smsg, smsg_len
mov
rax,[ans]
; load value of ans in rax
call
disp64_proc ; display
ans
print nline, nline_len
ret
mul64_proc:
mov rax,[no1]
mov rbx,[no2]
mul rbx
mov [ans], rax ; store
ans
print mmsg, mmsg_len
mov
rax,[ans]
; load value of ans in rax
call
disp64_proc ; display
ans
print nline, nline_len
ret
div64_proc:
mov rdx,00
mov rax,[no1]
mov rbx,[no2]
div rbx
;(rdx:rax)/rbx
mov [ans], rax ; store
ans
print dmsg, dmsg_len
mov
rax,[ans]
; load value of ans in rax
call
disp64_proc ; display
ans
print nline, nline_len
ret
disp64_proc:
mov
rsi,char_ans+15 ; load
last byte address of char_ans buffer in rsi
mov
rcx,16
; number of digits
cnt:
mov rdx,0
; make rdx=0 (as in div instruction rdx:rax/rbx)
mov
rbx,16
; divisor=16 for hex
div
rbx
cmp
dl, 09h
; check for remainder in RDX
jbe
add30
add
dl, 07h
add30:
add
dl,30h
; calculate ASCII code
mov
[rsi],dl
; store it in buffer
dec
rsi
; point to one byte back
dec
rcx
; decrement count
jnz
cnt
; if not zero repeat
print
char_ans,16 ; display result on screen
ret
-
OUTPUT
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 switch64.asm -o
switch64.oell-152@ell152-OptiPlex-390:~/Desktop$ ld -o switch64 switch64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./switch64
-Menu-
1. Addition
2. Subtraction
3. Multiplication
4. Division
Exit
Enter Your
Choice: 1
Addition Result is
: 0000000000224466
-Menu-
1. Addition
2. Subtraction
3. Multiplication
4. Division
Exit
Enter Your
Choice: 2
subtraction Result is
: 0000000000000000
-Menu-
1. Addition
2. Subtraction
3. Multiplication
4. Division
Exit
Enter Your
Choice: 3
multiplication Result is
: 000001258F579629
-Menu-
1. Addition
2. Subtraction
3. Multiplication
4. Division
Exit
Enter Your
Choice: 4
Division Result is
: 0000000000000001
-Menu-
1. Addition
2. Subtraction
3. Multiplication
4. Division
Exit
Enter Your
Choice:
Assignment No:08
Aim:Write an ALP to count no. of positive and negative numbers
from the array
section
.data
nline db 10,10
nline_len: equ $-nline
arr64 dq
-0000000011111111H, 22222222H, -33333333H, 44444444H, 55555555H
n: equ 5
pmsg db
10,10,"The no. of Positive elements from 64-bit array :
"
pmsg_len: equ $-pmsg
nmsg db
10,10,"The no. of Negative elements from 64-bit array :
"
nmsg_len: equ $-nmsg
-
Section .bss
p_count resq
1
n_count resq 1
char_count resb 16
; for 64-bit nos.
-
;you can change the
macros as per 64-bit convensions
%macro
print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
exit 0
mov eax, 1
mov
ebx, 0
int 80h
%endmacro
-
; If U ARE MODIFYING
32-BIT PROGRAM then
; Check line by line and
make all 'e' as 'r' and other modifications
; for 64-bit numbers
section
.text
global _start
_start:
mov rsi, arr64
mov rdi, n
mov rbx,0;
; counter for +ve nos.
mov rcx,0;
; counter for -ve nos.
next_num:
mov rax,[rsi] ;
take no. in RAX
Rol rax,1
; rotate left 1 bit to check for sign bit
jc negative
positive:
inc rbx
; no carry, so no. is +ve
jmp next
negative:
inc rcx
; carry, so no. is -ve
next:
add
rsi,8
; 64 bit nos i.e. 8 bytes
dec
rdi
jnz
next_num
mov [p_count], rbx
; store positive count
mov [n_count], rcx
; store negative count
print pmsg, pmsg_len
mov
rax,[p_count] ; load
value of p_count in rax
call
disp64_proc ; display
p_count
print
nmsg, nmsg_len
mov
rax,[n_count] ; load
value of n_count in rax
call
disp64_proc ; display
n_count
print nline, nline_len
exit
disp64_proc:
mov
rsi,char_count+15 ; load last byte address
of char_count buffer in rsi
mov
rcx,16
; number of digits
cnt:
mov rdx,0
; make rdx=0 (as in div instruction rdx:rax/rbx)
mov
rbx,16
; divisor=16 for hex
div
rbx
cmp
dl, 09h
; check for remainder in RDX
jbe
add30
add
dl, 07h
add30:
add
dl,30h
; calculate ASCII code
mov
[rsi],dl ; store it in
buffer
dec
rsi
; point to one byte back
dec
rcx
; decrement count
jnz
cnt
; if not zero repeat
print
char_count,16 ; display result on screen
ret
-
OUTPUT
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 pn64.asm -o pn64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o pn64 pn64.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./pn64
The no. of Positive
elements from 64-bit array : 0000000000000003
The no. of Negative
elements from 64-bit array : 0000000000000002
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No:10
Aim:Write ALP to find average of n numbers stored in memory
section .data
resmsg db 10,'Average = '
rmsg_len equ $-resmsg
array
dd 0ffff4587h,0f7ff89ffh, 0ffff0022h,0abcdffffh
arrcnt equ 04
avg
dd 0
section .bss
dispbuff resb 8
%macro print 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro
section .text
global _start
_start:
mov
esi,array
mov
eax,0
mov
edx,0
mov
ecx,arrcnt
up1:
add
eax,[esi]
adc
edx,0
add
esi,4
loop
up1
mov
ebx,arrcnt
div
ebx
mov
[avg],eax
print
resmsg,rmsg_len
mov
ebx,[avg]
call
disp32num
print
resmsg,1 ;New line char
mov
eax,01
mov
ebx,0
int
80h
disp32num:
mov
ecx,8
mov
edi,dispbuff
dup1:
rol
ebx,4
mov
al,bl
and
al,0fh
cmp
al,09
jbe
dskip
add
al,07h
dskip:
add al,30h
mov
[edi],al
inc
edi
loop
dup1
print
dispbuff,8
ret
OUTPUT
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 msmalb10.asm
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o msmalb10 msmalb10.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./msmalb10
Average = E8F2F3E9
ell-152@ell152-OptiPlex-390:~/Desktop$
Assignment No:11
Aim:Write program to read & display contents of file
;This is 32 bit code
;I have already created 'MAL_LAB.txt' file and written some text
in it.
;0777 is the PERMISSION MODE for this refer the document CHANING
FILE PERMISSIONS. I have attached this document with mail.
;Also refer the ebook ASSEMBLY LANGUAGE TUTORIAL---- CHAPTER 20
----Assembly File Management.
;I have attached this book also with this mail.
%macro DISPLAY 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro
section .data
file_name db 'MAL_LAB.txt',0
;'MAL_LAB.txt' is already created and contents are already present in it
msg
db 'FILE CONTENTS ARE:-',0xA,0xD
len
equ $-msg
msg1
db 'FILE READ SUCESSFULLY!',0xA,0xD
len1
equ $-msg1
section .bss
fd_in
resb 1 ;file decriptor
info
resb 2000 ;buffer
section .text
global _start
_start:
;open the file for reading
mov eax,5 ;system
call number (sys_open)
mov ebx,file_name ;file name
mov ecx,0 ; file
access mode
mov edx,0777
;read,write and execute by all
int 80h
;call kernel
mov [fd_in],eax ;
file descriptor
;read from file
mov eax,3 ;system
call number (sys_read)
mov ebx,[fd_in]
;file descriptor
mov ecx,info
;pointer to the input buffer
mov edx,2000
;buffer size i.e the number of bytes to read
int 80h
;call kernel
;close the file
mov eax,6 ;system
call number (sys_close)
mov ebx,[fd_in]
;file decriptor
DISPLAY msg,len
;print the info
mov eax,4
mov ebx,1
mov ecx,info
mov edx,2000
int 80h
DISPLAY msg1,len1
;exit
mov eax,1 ;system call number
(sys_exit)
int 80h ;call
kernel
OUTPUT
ell-152@ell152-OptiPlex-390:~/Desktop$
nasm -f elf64 fileread32bit.asm
ell-152@ell152-OptiPlex-390:~/Desktop$
ld -o fileread32bit fileread32bit.o
ell-152@ell152-OptiPlex-390:~/Desktop$
./fileread32bit
FILE CONTENTS ARE:-
DEPARTMENT OF COMPUTER
ENGINEERING
FILE READ SUCESSFULLY!
ell-152@ell152-OptiPlex-390:~/Desktop$
Group C
Assignment No:01
Aim:Write ALP to switch from real mode to protected mode and
display the values of GDTR,
LDTR, IDTR, TR and MSW Registers.
;using 64-bit registers
;This program first check the mode of processor(Real or
Protected),
;then reads GDTR, IDTR, LDTR, TR, MSW and displays the same.
section
.data
nline db 10,10
nline_len: equ $-nline
colon db
":"
rmsg
db 10,'Processor is in
Real Mode...'
rmsg_len: equ $-rmsg
pmsg
db 10,'Processor is in
Protected Mode...'
pmsg_len: equ $-pmsg
gmsg db
10,"GDTR (Global Descriptor Table Register) :
"
gmsg_len: equ $-gmsg
imsg db
10,"IDTR (Interrupt Descriptor Table Register) :
"
imsg_len: equ $-imsg
lmsg
db 10,"LDTR (Local Descriptor
Table Register) : "
lmsg_len: equ $-lmsg
tmsg db
10,"TR (Task Register) : "
tmsg_len: equ $-tmsg
mmsg db
10,"MSW (Machine Status Word) : "
mmsg_len: equ $-mmsg
-
Section .bss
GDTR resw
3 ; 48 bits, so 3 words
IDTR resw 3
LDTR resw
1 ; 16 bits, so 1 word
TR resw 1
MSW resw 1
char_sum resb 4
; 16-bits, so 4 digits
-
;you can change the
macros as per 64-bit convensions
%macro
print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
%macro
exit 0
mov eax, 1
mov ebx, 0
int 80h
%endmacro
-
; If U ARE MODIFYING 32-BIT PROGRAM then
; Check line by line and make all 'e' as 'r' and other
modifications
; for 64-bit numbers
section
.text
global _start
_start:
SMSW [MSW]
mov rax,[MSW]
ror
rax,1
; Check PE bit, if 1=Protected Mode, else Real Mode
jc
p_mode
print rmsg,rmsg_len
jmp next
p_mode:
print pmsg,pmsg_len
next:
SGDT [GDTR]
SIDT [IDTR]
SLDT [LDTR]
STR [TR]
;
SMSW [MSW]
print gmsg, gmsg_len
;GDTR (Global Descriptor Table Register)
; LITTLE ENDIAN SO TAKE LAST WORD FIRST
mov
ax,[GDTR+4] ; load
value of GDTR[4,5] in ax
call
disp16_proc ; display
GDTR contents
mov
ax,[GDTR+2] ; load
value of GDTR[2,3] in ax
call
disp16_proc ; display
GDTR contents
print colon,1
mov
ax,[GDTR+0] ; load
value of GDTR[0,1] in ax
call
disp16_proc ; display
GDTR contents
print imsg, imsg_len
;IDTR (Interrupt Descriptor Table Register)
mov
ax,[IDTR+4]
call
disp16_proc
mov
ax,[IDTR+2]
call
disp16_proc
print colon,1
mov
ax,[IDTR+0]
call
disp16_proc
print lmsg, lmsg_len
;LDTR (Local Descriptor Table Register)
mov
ax,[LDTR]
call
disp16_proc
print tmsg, tmsg_len
;TR (Task Register)
mov
ax,[TR]
call
disp16_proc
print mmsg, mmsg_len
;MSW (Machine Status Word)
mov
ax,[MSW]
call
disp16_proc
print nline, nline_len
exit
disp16_proc:
mov
rsi,char_sum+3 ; load
last byte address of char_sum buffer in rsi
mov
rcx,4
; number of digits
;
cwd
; eax = 00000000 ax, convert word to dword
;
cdq
; rax = 00000000 eax, convert dword to qword
cnt:
mov rdx,0
; make rdx=0 (as in div instruction
rdx:rax/rbx)
mov
rbx,16
; divisor=16 for hex
div
rbx
cmp
dl, 09h
; check for remainder in RDX
jbe
add30
add
dl, 07h
add30:
add
dl,30h
; calculate ASCII code
mov
[rsi],dl
; store it in buffer
dec
rsi
; point to one byte back
dec
rcx
; decrement count
jnz
cnt
; if not zero repeat
print
char_sum,4 ; display result on screen
ret
-
OUTPUT
Processor is in
Protected Mode...
GDTR (Global Descriptor
Table Register) : 1F304000:007F
IDTR (Interrupt
Descriptor Table Register) : 81DD1000:0FFF
LDTR (Local Descriptor
Table Register) : 0000
TR (Task
Register) : 0040
MSW (Machine Status
Word) : 003B
- Get link
- X
- Other Apps