Labels

Monday 7 November 2016

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.

Without Using String Specific Instructions
section .data
msg db "enter an offset",10
len: equ $-msg
arr1 db "se computer",10,0,0,0,0
len1: equ $-arr1

section  .bss

n resb 2

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

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

section .text

global  _start
_start:

disp msg,len
inn n,2

cmp byte[n],39h
jng skip
sub byte[n],07h
skip:
sub byte[n],30h

mov rsi,arr1+len1-1   ;seting pointer rsi & rdi to respective locations
mov rdi,rsi
mov cl,len1
xor rax,rax
mov al,[n]
add rdi,rax

up:
mov al,[rsi]
mov [rdi],al
dec rdi
dec rsi
dec cl
jnz up

disp arr1,len1+len1-1

mov rax,3ch
mov rdi,00
syscall

Using String Specific Instructions

section .data
msg db "enter an offset",10
len: equ $-msg
arr1 db "se computer",10,0,0,0,0
len1: equ $-arr1


section  .bss
n resb 2

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

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

section .text

global  _start
_start:

disp msg,len
inn n,2

cmp byte[n],39h
jng skip
sub byte[n],07h
skip:
sub byte[n],30h

mov rsi,arr1+len1-1   ;seting pointer rsi & rdi to respective locations
mov rdi,rsi
mov rcx,len1
xor rax,rax
mov al,[n]
add rdi,rax

std
rep movsb

disp arr1,len1+len1-1

mov rax,3ch
mov rdi,00
syscall

No comments:

Post a Comment