Problem Statement: Write X86/64 ALP to perform non-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(non overlapped): ",10
len4: equ $-msg4
msg5: db 10
len5: equ $-msg5
msg7: db " "
len7: equ $-msg7
SECTION .bss
array1 resb 100
array2 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
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
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
mov r9,array1
mov r10,array2
;mov al,byte[count2]
;mov byte[count2],al
loop1:
mov dl,[r9]
mov [r10],dl
inc r10
inc r9
dec byte[count2]
jnz loop1
print msg3,len3
mov r14,array1
call hex_asc
mov bl,byte[count4]
mov byte[count3],bl
print msg4,len4
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 msg7,len7
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
%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(non overlapped): ",10
len4: equ $-msg4
msg5: db 10
len5: equ $-msg5
msg7: db " "
len7: equ $-msg7
SECTION .bss
array1 resb 100
array2 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
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
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
mov r9,array1
mov r10,array2
;mov al,byte[count2]
;mov byte[count2],al
loop1:
mov dl,[r9]
mov [r10],dl
inc r10
inc r9
dec byte[count2]
jnz loop1
print msg3,len3
mov r14,array1
call hex_asc
mov bl,byte[count4]
mov byte[count3],bl
print msg4,len4
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 msg7,len7
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 nonoverl.lst
nonoverl.asm
amodi@ubuntu:~/MIL/Assign2$ ld -o nonoverl nonoverl.o
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
amodi@ubuntu:~/MIL/Assign2$ ./nonoverl
Enter quantity of numbers: 06
Enter numbers in the array:
12
23
34
45
56
67
Numbers in the original position:
12 000000000060044C
23 000000000060044D
34 000000000060044E
45 000000000060044F
56 0000000000600450
67 0000000000600451
Numbers in the new position(non overlapped):
12 00000000006004B0
23 00000000006004B1
34 00000000006004B2
45 00000000006004B3
56 00000000006004B4
67 00000000006004B5
amodi@ubuntu:~/MIL/Assign2$ ld -o nonoverl nonoverl.o
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
amodi@ubuntu:~/MIL/Assign2$ ./nonoverl
Enter quantity of numbers: 06
Enter numbers in the array:
12
23
34
45
56
67
Numbers in the original position:
12 000000000060044C
23 000000000060044D
34 000000000060044E
45 000000000060044F
56 0000000000600450
67 0000000000600451
Numbers in the new position(non overlapped):
12 00000000006004B0
23 00000000006004B1
34 00000000006004B2
45 00000000006004B3
56 00000000006004B4
67 00000000006004B5
No comments:
Post a Comment