Saturday, April 19, 2014

Overlapped Block Data Transfer in NASM[x86/64 architecture]



Problem Statement: Write X86/64 ALP to perform overlapped block transfer. Block containing data can be defined in the data segment.
 
%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
msg1: db "Enter quantity of numbers: "
len1: equ $-msg1
msg2: db "Enter numbers in the array: ",10
len2: equ $-msg2
msg3: db "Numbers in the original position: ",10
len3: equ $-msg3
msg4: db "Numbers in the new position(overlapped): ",10
len4: equ $-msg4
msg5: db 10
len5: equ $-msg5
msg6: db "   "
len6: equ $-msg6

SECTION .bss
array1 resb 100
num: resb 3
n: resb 3
adr: resb 16
count: resb 2
cnt: resb 2
count1: resb 2
count2: resb 2
count3: resb 2
count4: resb 2
ol: resb 2

SECTION .text
global main
main:

print msg1,len1
accept num,3
call asc_hex
mov byte[count1],bl
mov byte[count2],bl
mov byte[count3],bl
mov byte[count4],bl
mov byte[ol],bl
shr [ol],1

print msg2,len2
mov r9,array1
array_input:
   accept num,3
   call asc_hex
   mov [r9],bl
   inc r9
   dec byte[count1]
   jnz array_input

print msg3,len3
mov r14,array1
call hex_asc


mov bl,byte[count4]
mov byte[count3],bl
dec r14
loop1:
mov dl,[r14]
mov r10,r14
add r10,[ol]
mov [r10],dl
dec r14
dec byte[count2]
jnz loop1

mov r14,array1
add r14,[ol]
print msg4,len4
call hex_asc

;mov r14,array2
;call hex_asc

mov rax,60
mov rdi,1
syscall

asc_hex:
mov ch,02
mov bl,00
mov r10,0
loop:
    mov al,[num+r10]
    cmp al,61H
    jb next
    sub al,57H
    jmp next2
next:
    cmp al,41h
    jb next1
    sub al,37H
    jmp next2
next1:
     sub al,30H
next2:
     shl bl,04H
     add bl,al
     inc r10
     dec ch
     jnz loop
ret

hex_asc:
mov al,[r14]
;mov [n],al
mov r15,n
mov byte[count],2
l1:
    rol al,04H
    mov dl,al
    and dl,0FH
    cmp dl,09H
    jbe l2
    add dl,07H
    l2:
    add dl,30H
     mov[r15],dl
     inc r15
    dec byte[count]
    jnz l1
print n,2
print msg6,len6

mov byte[cnt],16
mov rbx,r14
mov r11,adr
ll1:
    rol rbx,04H
    mov dl,bl
    and dl,0FH
    cmp dl,09H
    jbe ll2
    add dl,07H
    ll2:
     add dl,30H
    mov [r11],dl
    inc r11
    dec byte[cnt]
    jnz ll1

print adr,16
inc r14
dec byte[count3]
print msg5,len5
jnz hex_asc
ret

Output

amodi@ubuntu:~/MIL/Assign2$ nasm -f elf64 -l overl.lst overl.asm
amodi@ubuntu:~/MIL/Assign2$ ld -o overl overl.o
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
amodi@ubuntu:~/MIL/Assign2$ ./overl
Enter quantity of numbers: 05
Enter numbers in the array:
12
23
34
45
22
Numbers in the original position:
12   000000000060044C
23   000000000060044D
34   000000000060044E
45   000000000060044F
22   0000000000600450
Numbers in the new position(overlapped):
12   000000000060044E
23   000000000060044F
34   0000000000600450
45   0000000000600451
22   0000000000600452
 

No comments:

Post a Comment

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...