102 lines
1.4 KiB
NASM
102 lines
1.4 KiB
NASM
|
; THIS CODE HAS BEEN TESTED AND IS FULLY OPERATIONAL.
|
||
|
|
||
|
; Problem Statement: Write X86/64 ALP to perform non-overlapped block transfer (WITHOUT string specific instructions). Block containing data can be defined in the data segment.
|
||
|
|
||
|
; Code from Microprocessor (SPPU - Second Year - Computer Engineering - Content) repository on KSKA Git: https://git.kska.io/sppu-se-comp-content/Microprocessor/
|
||
|
|
||
|
|
||
|
; BEGINNING OF CODE
|
||
|
%macro print 2
|
||
|
mov rax,1
|
||
|
mov rdi,1
|
||
|
mov rsi,%1
|
||
|
mov rdx,%2
|
||
|
syscall
|
||
|
%endmacro
|
||
|
|
||
|
section .data
|
||
|
m1 db 10,"Source block:",10,13
|
||
|
m1len equ $-m1
|
||
|
|
||
|
m2 db 10,"Destination block after transfer:",10,13
|
||
|
m2len equ $-m2
|
||
|
|
||
|
space db" "
|
||
|
spacelen equ $-space
|
||
|
|
||
|
srcblk db 10h,20h,30h,40h,50h
|
||
|
|
||
|
count equ 05h
|
||
|
|
||
|
section .bss
|
||
|
ans resb 4
|
||
|
dstblk resb 5
|
||
|
|
||
|
section .text
|
||
|
global _start
|
||
|
_start:
|
||
|
print m1,m1len
|
||
|
mov rsi,srcblk
|
||
|
call disp_block
|
||
|
|
||
|
print m2,m2len
|
||
|
|
||
|
mov rsi,srcblk
|
||
|
mov rdi,dstblk
|
||
|
mov rcx,05
|
||
|
|
||
|
s1: mov al,[rsi]
|
||
|
mov [rdi],al
|
||
|
inc rsi
|
||
|
inc rdi
|
||
|
loop s1
|
||
|
|
||
|
mov rsi,dstblk
|
||
|
call disp_block
|
||
|
|
||
|
mov rax,60
|
||
|
xor rdi,rdi
|
||
|
syscall
|
||
|
|
||
|
disp_block:
|
||
|
mov rbp,count
|
||
|
back:mov al,[rsi]
|
||
|
push rsi
|
||
|
call disp_8
|
||
|
print space,1
|
||
|
pop rsi
|
||
|
inc rsi
|
||
|
dec rbp
|
||
|
jnz back
|
||
|
ret
|
||
|
|
||
|
disp_8:mov rsi,ans
|
||
|
|
||
|
mov bl,al
|
||
|
mov dl,bl
|
||
|
rol dl,04
|
||
|
and dl,0fh
|
||
|
cmp dl,09h
|
||
|
jbe add30
|
||
|
add dl,07h
|
||
|
|
||
|
add30:
|
||
|
add dl,30h
|
||
|
mov [rsi],dl
|
||
|
inc rsi
|
||
|
|
||
|
mov dl,bl
|
||
|
and dl,0fh
|
||
|
cmp dl,09h
|
||
|
jbe add130
|
||
|
add dl,07h
|
||
|
|
||
|
add130:
|
||
|
|
||
|
add dl,30h
|
||
|
mov [rsi],dl
|
||
|
|
||
|
print ans,2
|
||
|
ret
|
||
|
; END OF CODE
|