Categories
SE Computer Engineering

7. Write X86 program to sort the list of integers in ascending/descending order. Read the input from the text file a nd write the sorted data back to the same text file using bubble sort.

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro file 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro

Section .data
openmsg db 10,13,”File Opened Successfully”
openmsg_len equ $-openmsg

closemsg db 10,13,”File Closed Successfully”
closemsg_len equ $-closemsg

errormsg db 10,13,”Failed to open file”, 0xa
errormsg_len equ $-errormsg

space db ” “
space_len equ $ – space

sortmsg db 10,13,”After Sorting “
sortmsg_len equ $-sortmsg

f1name db ‘input.txt’

Section .bss
buffer resb 200
bufercpy resb 200
bufferlen resb 8
cnt1 resb 8
cnt2 resb 8
fdisplay resb 8

Section .text
global _start
_start:

file 2, f1name, 2, 777      ;Opening file

mov qword[fdisplay], rax      ;RAX contains file descriptor value
bt rax, 63             ;63rd bit is +ve(0) if file is successfull opened else it is -ve (1)
                        ;Here we are checking for MSB if MSB is 1 that means -ve and if MSB is 0 that means +ve
jc ERROR

print openmsg, openmsg_len
jmp next1

ERROR:
print errormsg, errormsg_len
jmp EXIT

next1:
file 0,[fdisplay] ,buffer,200     ;reading contents of file in buffer
                     ;rax contains actual number of bytes read
 mov qword[bufferlen],rax         ;for rounds
 mov qword[cnt1],rax
 mov qword[cnt2],rax

BUBBLE:
mov al,byte[cnt2]
 mov byte[cnt1],al
 dec byte[cnt1]

mov rsi,buffer
mov rdi,buffer+1

loop:
mov bl,byte[rsi]
mov cl,byte[rdi]
 cmp bl,cl
 ja SWAP
 inc rsi
 inc rdi
 dec byte[cnt1]
 jnz loop
dec byte[bufferlen]
jnz BUBBLE
jmp END
SWAP:
 ;mov al,byte[rsi]
 mov byte[rsi],cl
 mov byte[rdi],bl
 inc rsi
 inc rdi
 dec byte[cnt1]
 jnz loop
dec byte[bufferlen]
jnz BUBBLE

END:
print sortmsg,sortmsg_len
print buffer,qword[cnt2]

file 1,qword[fdisplay],sortmsg,sortmsg_len      ;writing to input.txt
file 1,qword[fdisplay],buffer,qword[cnt2]          ;writing to input.txt

;Closing file2

mov rax,3
mov rdi,f1name
syscall
print closemsg,closemsg_len

EXIT:
 mov rax,60
 mov rdi,0
 syscall

input.txt (Store following numbers in the file)
6 3 1 5 2 9 8 7

OUTPUT:
swlab@swlab-H81-M1:~$ nasm -f elf64 bsort.asm
swlab@swlab-H81-M1:~$ ld -o bsort bsort.o
swlab@swlab-H81-M1:~$ ./bsort

File Opened Successfully
After Sorting
       12356789
File Closed Successfully

swlab@swlab-H81-M1:~$

Categories
SE Computer Engineering

6. Write X86/64 ALP to switch from real mode to protected mode and display the values of GDTR, LDTR, IDTR, TR and MSW Registers.

;This program first check the mode of processor(Real or Protected),
;then reads GDTR, LDTR, IDTR, TR & MSW and displays the same.

%macro disp 2
mov eax,04
mov ebx,01
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .data
rmodemsg db 10,13,”Processor is in Real Mode”
rmsg_len equ $-rmodemsg

pmodemsg db 10,13,”Processor is in Protected Mode”
pmsg_len:equ $-pmodemsg

gdtmsg db 10,13,”GDT Contents are::”
gmsg_len:equ $-gdtmsg

ldtmsg db 10,13,”LDT Contents are::”
lmsg_len equ $-ldtmsg

idtmsg db 10,13,”IDT Contents are::”
imsg_len equ $-idtmsg

trmsg db 10,13,”Task Register Contents are::”
tmsg_len equ $-trmsg

mswmsg db 10,13,”Machine Status Word::”

mmsg_len:equ $-mswmsg
colmsg db ‘:’

nwline db 10

section .bss
gdt resd 1
    resw 1

ldt resw 1

idt resd 1
    resw 1

tr  resw 1
cr0_data resd 1
dnum_buff resb 04

section .text
global _start

_start:
smsw eax        ;Reading CR0
mov [cr0_data],eax
bt eax,0        ;Checking PE bit(LSB), if 1=Protected Mode, else Real Mode
jc prmode
disp rmodemsg,rmsg_len
jmp nxt1

prmode:   
disp pmodemsg,pmsg_len

nxt1:   
sgdt [gdt]
sldt [ldt]
sidt [idt]
str [tr]

disp gdtmsg,gmsg_len
mov bx,[gdt+4]
call disp_num

mov bx,[gdt+2]
call disp_num

disp colmsg,1
mov bx,[gdt]
call disp_num

disp ldtmsg,lmsg_len
mov bx,[ldt]
call disp_num

disp idtmsg,imsg_len
mov bx,[idt+4]
call disp_num

mov bx,[idt+2]
call disp_num

disp colmsg,1
mov bx,[idt]
call disp_num

disp trmsg,tmsg_len
mov bx,[tr]
call disp_num

disp mswmsg,mmsg_len
mov bx,[cr0_data+2]
call disp_num

mov bx,[cr0_data]
call disp_num

disp nwline,1

exit:   
mov eax,01
mov ebx,00
int 80h

disp_num:
mov esi,dnum_buff     ;point esi to buffer
mov ecx,04        ;load number of digits to display

up1:
rol bx,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 skip1        ;if less than 39h skip adding 07 more
add dl,07h        ;else add 07

skip1:
mov [esi],dl        ;store ASCII code in buffer
inc esi            ;point to next byte
dec ecx
jnz up1            ;decrement the count of digits to display
            ;if not zero jump to repeat
disp dnum_buff,4    ;display the number from buffer
ret

OUTPUT:
swlab@swlab-H81-M1:~$ nasm -f elf msw.asm
swlab@swlab-H81-M1:~$ ld -m elf_i386 -s -o msw msw.o
swlab@swlab-H81-M1:~$ ./msw

Processor is in Protected Mode
GDT Contents are::1FA89000:007F
LDT Contents are::0000
IDT Contents are::FF578000:0FFF
Task Register Contents are::0040
Machine Status Word::80050033
swlab@swlab-H81-M1:~$

Categories
SE Computer Engineering

5. Write X86 ALP to find, a) Number of Blank spaces b) Number of lines c) Occurrence of a particular character. Accept the data from the text file. The text file has to be accessed during Program_1 execution and write FAR PROCEDURES in Program_2 for the rest of the processing. Use of PUBLIC and EXTERN directives is mandatory.

f1.asm
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro

Section .data

title db 10,13,”****ASSIGNMENT: 5****”
title_len equ $-title
openmsg db 10,13,”File Opened Successfully”
openmsg_len equ $-openmsg
errormsg db 10,13,”Failed to open file”
errormsg_len equ $-errormsg

fname db “abc.txt”

Section .bss
global cnt1,cnt2,cnt3,buffer,bufferlen,fdis
cnt1 resb 8
cnt2 resb 8
cnt3 resb 8
bufferlen resb 8
buffer resb 200
fdis resq 1                     ;for storing file descriptor value

Section .text
global _start
extern CSPACE,CNEWLINE,CCHAR
start:
print title,title_len

;Opening file
mov rax,2
mov rdi,fname
mov rsi,2
mov rdx,777
syscall

mov qword[fdis],rax            ;RAX contains file descriptor value
bt rax,63                      ;63rd bit is +ve(0) if file is successfull opened else it is -ve (1)
jc next

print openmsg,openmsg_len
jmp next1

next:
 print errormsg,errormsg_len
 jmp EXIT

next1:
;reading contents of file in buffer
mov rax,0
mov rdi,[fdis]
mov rsi,buffer
mov rdx,200
syscall
                                ;rax contains actual number of bytes read
 mov qword[bufferlen],rax
 mov qword[cnt1],rax             ;cnt1 for using in cspace procedure
 mov qword[cnt2],rax             ;cnt2 for using in cnewline procedure
 mov qword[cnt3],rax             ;cnt3 for using in cchar procedure

call CCHAR
call CSPACE
call CNEWLINE

mov rax,3
mov rdi,fname
syscall

EXIT:
mov rax,60
mov rdi,0
syscall

f2.asm
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .data
spacemsg db 10,13,”Spaces = “
spacemsg_len equ $-spacemsg

newlinemsg db  10,13, “Return(Enter) chars = “
newlinemsg_len equ $-newlinemsg

chms db 10,13,”Character count: “
chms_len equ $-chms

chinput db 10,13,”Character Input: “,
chinput_len equ $-chinput

scnt db 00H
ncnt db 00H
chcnt db 00H
hexcnt2 db 00H

section .bss
extern cnt1,cnt2,cnt3,buffer,bufferlen
spacecount resb 2
ch1 resb 2
newlinecount resb 2
chcount resb 2

section .text
global _start1
global CSPACE, CNEWLINE,CCHAR
_start1:

CSPACE:
 mov rsi,buffer
up:
 mov al,byte[rsi]
 cmp al,20H
 je next2
 inc rsi
 dec qword[cnt1]
 jnz up
 jmp next3

next2:
 inc byte[scnt]
 inc rsi
 dec qword[cnt1]
 jmp up

next3:
 mov bl, byte[scnt]
 mov rdi, spacecount
 call HtoA

 print spacemsg,spacemsg_len
 print spacecount,2

ret

CNEWLINE:
 mov rsi,buffer
up2:
 mov al,byte[rsi]
 cmp al,0x0A
 je next4
 inc rsi
 dec qword[cnt2]
 jnz up2
 jmp next5

next4:
 inc byte[ncnt]
 inc rsi;
 dec qword[cnt2]
 jnz up2

next5:
 mov bl, byte[ncnt]
 mov rdi, newlinecount
 call HtoA

 print newlinemsg,newlinemsg_len
 print newlinecount,2

ret

CCHAR:
 print chinput,chinput_len
 accept ch1,2
 mov rsi,buffer
up3:
 mov al,byte[rsi]
 cmp al,byte[ch1]
 je nextl
 inc rsi
 dec qword[cnt3]
 jnz up3
 jmp next7

nextl:
 inc byte[chcnt]
 inc rsi;
 dec qword[cnt3]
 jnz up3

next7:
 mov bl, byte[chcnt]
 mov rdi, chcount
 call HtoA
 print chms,chms_len
 print chcount,2

ret
;——HEX TO ASCII CONVERSION METHOD FOR VALUE(2 DIGIT) —————-

HtoA:             ;hex_no to be converted is in ebx //result is stored in rdi/user defined variable
mov byte[hexcnt2],02H
h2aup:
rol bl,04
mov cl,bl
and cl,0FH
CMP CL,09H
jbe add30
ADD cl,07H

add30:
add cl, 30H
mov byte[rdi],cl
INC rdi
dec byte[hexcnt2]
JNZ h2aup
ret

exit:
mov rax,60
mov rdi,0
syscall
abc.txt

Welcome SE computer student in SVIT College, Chincholi, Sinner, Dist: Nashik
How are you

OUTPUT:
ntlab@ntlab-Veriton-M200-H81:~/file$ nasm -f elf64 f1.asm
ntlab@ntlab-Veriton-M200-H81:~/file$ nasm -f elf64 f2.asm
ntlab@ntlab-Veriton-M200-H81:~/file$ ld -o prog f1.o f2.o
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
ntlab@ntlab-Veriton-M200-H81:~/file$ ./prog

****ASSIGNMENT: 5****
File Opened Successfully
Character Input: c

Character count: 03
Spaces = 0C
Return(Enter) chars = 03

ntlab@ntlab-Veriton-M200-H81:~/file$ 

Categories
SE Computer Engineering

4. Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. Use successive addition and add and shift method.

;Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. ;Use successive addition and add and shift method.
;Accept input from the user. (use of 64-bit registers is expected)

;——————————p5.asm————————————————
%macro dispmsg 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro accept 2
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .data

msg db 10,”Enter two digit Number::”
msg_len equ $-msg
res db 10,”Multiplication of elements is::”
res_len equ $-res
choice     db 10,13,”****MENU****”
    db 10,13,”1.Successive Addition”
    db 10,13,”2.Add and Shift method”
    db 10,13,”3.Exit”
    db 10,13,”Enter choice=”
choice_len equ $-choice

section .bss
num resb 03
num1 resb 01
result resb 04
cho resb 2

section .text

global _start
_start:

dispmsg choice,choice_len
accept cho,2

cmp byte[cho],”1″
je a

cmp byte[cho],”2″
je b

jmp exit

a:
call Succe_addition
jmp _start

b:
call Add_shift
jmp _start

exit:
mov eax,1
int 80h

convert:
mov ebx,0
mov ecx,0
mov eax,0

mov ecx,02
mov esi,num
up1:
rol bl,04
mov al,[esi]
cmp al,”9″
jbe sub30
sub al,37h

sub30:
sub al,30h
add bl,al
inc esi
dec ecx
jnz up1
ret

display:
mov ecx,4
mov edi,result
dup1:
rol bx,4
mov al,bl
and al,0fh
cmp al,09h
jg p3
add al,30h
jmp p4
p3: add al,37h
p4:mov [edi],al
inc edi
loop dup1

dispmsg result,4
ret

Succe_addition:
dispmsg msg,msg_len
accept num,3
call convert
mov [num1],bl

dispmsg msg,msg_len
accept num,3
call convert
mov ecx,0
mov eax,0
mov eax,[num1]

repet:
add ecx,eax
dec bl
jnz repet

mov [result],ecx
dispmsg res,res_len
mov ebx,[result]

call display
ret

Add_shift:
dispmsg msg,msg_len
accept num,3

call convert
mov [num1],bl

dispmsg msg,msg_len
accept num,3
call convert

mov [num],bl

mov ebx,0
mov ecx,0
mov edx,0
mov eax,0
mov dl,08
mov al,[num1]
mov bl,[num]

p11:
shr bx,01
jnc p
add cx,ax
p:
shl ax,01
dec dl
jnz p11

mov [result],ecx
dispmsg res,res_len
mov ebx,[result]
call display
ret

OUTPUT:
swlab@swlab-Veriton-M200-H81:~$ nasm -f elf mult.asm
swlab@swlab-Veriton-M200-H81:~$ ld -m elf_i386 -s -o mult mult.o
swlab@swlab-Veriton-M200-H81:~$ ./mult

****MENU****
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=1

Enter two digit Number::03

Enter two digit Number::05

Multiplication of elements is::000F
****MENU****
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=2

Enter two digit Number::03

Enter two digit Number::04

Multiplication of elements is::000C
****MENU****
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=3
swlab@swlab-Veriton-M200-H81:~$

Categories
SE Computer Engineering

3. Write X86/64 ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit BCD number into its equivalent HEX number. Make your program user friendly to accept the choice from user for: (a) HEX to BCD b) BCD to HEX (c) EXIT.

%macro dispmsg 2
mov eax,04
mov ebx,01
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro accept 2
mov eax,03
mov ebx,00
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro exit 0
dispmsg thankmsg,thankmsg_len
mov eax,01        ;Exit
mov ebx,00
int 80h
%endm exit

section .data
menumsg db 10,10,”###### Menu for Code Conversion ######”
db 10,13,”1: Hex to BCD”
db 10,13,”2: BCD to Hex”
db 10,13,”3: Exit”
db 10,10,”Please Enter Choice::”
menumsg_len equ $-menumsg
wrchmsg db 10,10,”Wrong Choice Entered….Please try again!!!”
wrchmsg_len equ $-wrchmsg

hexinmsg db 10,10,”Please enter 4 digit hex number::”
hexinmsg_len equ $-hexinmsg

bcdopmsg db 10,10,”BCD Equivalent::”
bcdopmsg_len equ $-bcdopmsg

bcdinmsg db 10,10,”Please enter 5 digit BCD number::”
bcdinmsg_len equ $-bcdinmsg

hexopmsg db 10,10,”Hex Equivalent::”
hexopmsg_len equ $-hexopmsg

thankmsg db 10,13,”Thank you for using Program by Prof. Dhokane Rahul”
thankmsg_len equ $-thankmsg

section .bss
numascii resb 06        ;common buffer for choice, hex and bcd input
opbuff resb 05
dnumbuff resb 08

section .text
global _start
_start:

dispmsg menumsg,menumsg_len
accept numascii,2

cmp byte[numascii],”1″
jne case2
call hex2bcd_proc

jmp _start

case2:   
cmp byte [numascii],”2″
jne case3
call bcd2hex_proc
jmp _start

case3:    cmp byte [numascii],”3″
je ext
dispmsg wrchmsg,wrchmsg_len
jmp _start

ext:
exit

hex2bcd_proc:
dispmsg hexinmsg,hexinmsg_len
accept numascii,5
call packnum
mov ecx,5
mov ax,bx
mov bx,10
h2bup1:   
mov dx,0
div bx
push edx
dec ecx
jnz h2bup1

mov edi,opbuff
mov ecx,5
h2bup2:   
pop edx
add dl,30h
mov [edi],dl
inc edi
dec ecx
jnz h2bup2

dispmsg bcdopmsg,bcdopmsg_len
dispmsg opbuff,5
ret

bcd2hex_proc:
dispmsg bcdinmsg,bcdinmsg_len
accept numascii,6

dispmsg hexopmsg,hexopmsg_len

mov esi,numascii
mov ecx,05
mov eax,0
mov ebx,0ah

b2hup1:   
mov edx,0
mul ebx
mov dl,[esi]
sub dl,30h
add eax,edx
inc esi
dec ecx
jnz b2hup1
mov ebx,eax
call disp32_num
ret

packnum:
mov bx,0
mov ecx,04
mov esi,numascii
up1:
rol bx,04
mov al,[esi]
cmp al,”9″
jbe sub30
cmp al,”F”
jbe sub37
cmp al,”f”
jbe sub57
sub57:    sub al,20h
sub37:    sub al,07h
sub30:    sub al,30h
add bl,al
inc esi
dec ecx
jnz up1
ret

disp32_num:
mov edi,dnumbuff    ;point esi to buffer

mov ecx,08        ;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 adding 07 more
add dl,07h        ;else add 07

dispskip1:
mov [edi],dl        ;store ASCII code in buffer
inc edi            ;point to next byte
dec ecx
jnz dispup1        ;decrement the count of digits to display
;if not zero jump to repeat

dispmsg dnumbuff+3,5
ret

OUTPUT:
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ nasm -f elf h2b.asm
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ ld -m elf_i386 -s -o h2b h2b.o
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ ./h2b

###### Menu for Code Conversion ######
1: Hex to BCD
2: BCD to Hex
3: Exit

Please Enter Choice::1

Please enter 4 digit hex number::ffff

BCD Equivalent::65535

###### Menu for Code Conversion ######
1: Hex to BCD
2: BCD to Hex
3: Exit

Please Enter Choice::2

Please enter 5 digit BCD number::65535

Hex Equivalent::0FFFF

###### Menu for Code Conversion ######
1: Hex to BCD
2: BCD to Hex
3: Exit

Please Enter Choice::3

Thank you for using Program by Prof. Dhokane Rahul

Categories
SE Computer Engineering

2. Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without string specific instructions). Block containing data can be defined in the data segment.

;Write X86/64 ALP to perform non-overlapped and overlapped block transfer
;(with and without string specific instructions).
;Block containing data can be defined in the data segment.
;Macro Deffination
;—————————————————————————————
%macro exit 0
mov eax,1
mov ebx,0
int 80h
%endm exit

%macro accept 2  ;macro for read
mov eax,3        ;system call for read
mov ebx,0
mov ecx,%1
mov edx,%2       ;format for collecting arguments(as buffer_name & buffer_size)
int 80h
%endmacro

%macro disp 2   ;macro for display
mov eax,4       ;system call for display
mov ebx,1
mov ecx,%1      ;format for collecting arguments(as buffer_name & buffer_size)
mov edx,%2
int 80h
%endmacro

section .data
srcblk db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0Ah
destblk times 10 db 00

mn    db 10,13,”*****MENU*****”
db 10,13,”1.Non Overlap Block Transfer”
db 10,13,”2.Overlap Block Transfer”
db 10,13,”3.Exit”
db 10,13,”Enter Choice=”
mnlen equ $-mn

msg0 db ” “
msg0len equ $-msg0

msg1 db 10,13,”Array before bloktransfer”
len1 equ $-msg1

msg2 db 10,13,”Array after bloktransfer=”
len2 equ $-msg2

msg3 db 10,13,”Source Array=”
len3 equ $-msg3

msg4 db 10,13,”Dest Array=”
len4 equ $-msg4

newln db 10,13,””
lnlen equ $-newln

cnt equ 10

section .bss
cho resb 2
chlen equ $-cho
ansfin resb 2
ansfinlen equ $-ansfin

section .text
global _start
_start:
disp newln,lnlen
disp mn,mnlen
accept cho,2
cmp byte[cho],”1″
je nonover
cmp byte[cho],”2″
je ovr
disp newln,lnlen
exit

ovr:
call over

nonover:
disp msg1,len1
disp msg3,len3
mov esi,srcblk
mov ebp,10
call display

disp msg4,len4
mov esi,destblk
mov ebp,10
call display

disp newln,lnlen
disp msg2,len2
disp msg3,len3
mov esi,srcblk
mov ebp,10
call display

mov esi,srcblk
mov edi,destblk
mov ecx,10
cld
rep movsb

disp msg4,len4
mov esi,destblk
mov ebp,10
call display
jmp _start

over:
disp msg1,len1
disp msg3,len3
mov esi,srcblk
mov ebp,10
call display

disp msg4,len4
mov esi,destblk
mov ebp,10
call display

disp newln,lnlen
disp msg2,len2
disp msg3,len3
mov esi,srcblk
mov ebp,cnt
call display

mov esi,srcblk
mov edi,destblk
mov ecx,10
cld
rep movsb

mov esi,srcblk
mov edi,destblk+5
mov ecx,5
cld
rep movsb

disp msg4,len4
mov esi,destblk
mov ebp,10
call display
jmp _start

numascii:
mov edi,ansfin+1
mov ecx,2
l2:
mov edx,0
mov ebx,16
div ebx
cmp dl,09h
jbe add30
add dl,07h
add30:
add dl,30h
mov [edi],dl
dec edi
dec ecx
jnz l2
disp ansfin,ansfinlen
ret

display:
l1:
mov eax,[esi]
call numascii
disp msg0,msg0len
inc esi
dec ebp
jnz l1
ret

OUTPUT:
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ nasm -f elf over.asm
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ ld -m elf_i386 -s -o over over.o
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ ./over

*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=1

Array before bloktransfer
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=00 00 00 00 00 00 00 00 00 00

Array after bloktransfer=
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 06 07 08 09 0A

*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=2

Array before bloktransfer
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 06 07 08 09 0A

Array after bloktransfer=
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 01 02 03 04 05

*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=3

Categories
SE Computer Engineering

1. Write X86/64 ALP to count number of positive and negative numbers from the array.

;Write X86/64 ALP to count number of positive and negative numbers from the

;array

%macro print 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .data
arr dd -18888888h,18888888h,22222222h,11111111h
n equ 4
pmsg db 10,13,”The Count of Positive No: ”
plen equ $-pmsg
nmsg db 10,13,”The Count of Negative No: ”
nlen equ $-nmsg
nwline db 10,13
th db 10,13,”Program developed by Prof Dhokane R.M.(SVIT, Chincholi, Nashik)”
thlen equ $-th

section .bss
pcnt resq 1
ncnt resq 1
char_answer resb 8

section .text
global _start
_start:
mov esi,arr
mov edi,n
mov ebx,0
mov ecx,0

up:
mov eax,[esi]
cmp eax,00000000h
js negative

positive:       inc ebx
jmp next
negative:       inc ecx

next:   add esi,4
dec edi
jnz up

mov [pcnt],ebx
mov [ncnt],ecx

print pmsg,plen
mov eax,[pcnt]
call display

print nmsg,nlen
mov eax,[ncnt]
call display

print th,thlen
print nwline,1

mov eax,1
mov ebx,0
int 80h

;display procedure for 32bit
display:
mov esi,char_answer+7
mov ecx,8

cnt:    mov edx,0
mov ebx,16h
div ebx
cmp dl,09h
jbe add30
add dl,07h
add30:  add dl,30h
mov [esi],dl
dec esi
dec ecx
jnz cnt
print char_answer,8
ret

OUTPUT:
swlab@swlab-Veriton-M200-H81:~$ nasm -f elf pn.asm
swlab@swlab-Veriton-M200-H81:~$ ld -m elf_i386 -s -o pn pn.o
swlab@swlab-Veriton-M200-H81:~$ ./pn

The Count of Positive No: 00000003
The Count of Negative No: 00000001
Program developed by Prof Dhokane R.M.(SVIT, Chincholi, Nashik)