Labels

Monday 7 November 2016

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)

Program for multiplication of two 8 bit numbers by successive addition

section .data
msg1 db "enter first 8 bit hex no:",10
len1: equ $-msg1
msg2 db "enter second 8 bit hex no:",10
len2: equ $-msg2
msg3 db "Multiplication of two hex no is:",10
len3: equ $-msg3

section .bss

arr1 resb 3
arr2 resb 3
arr3 resb 4

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

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

section .text
global _start
_start:

disp msg1,len1
inn arr1,03

disp msg2,len2
inn arr2,03

mov rsi,arr1
mov cl,04
xor bx,bx
mov ch,02
up:
cmp byte[rsi],39h
jng sk
sub byte[rsi],07h
sk:
sub byte[rsi],30h
shl bx,cl
add  bl,[rsi]
inc rsi
dec ch
jnz up

xor dx,dx
mov rsi,arr2
mov cl,04
mov ch,02
up1:
cmp byte[rsi],39h
jng sk1
sub byte[rsi],07h
sk1:
sub byte[rsi],30h
shl dx,cl
add dl,[rsi]

inc rsi
dec ch
jnz up1

xor ax,ax
xor cl,cl
cmp dl,bl
jng sph
mov cl,bl
mov bl,dl
jmp outt
sph:
mov cl,dl
outt:
add ax,bx
dec cl
jnz outt


mov rsi,arr3
mov ch,04
mov cl,04
again1:
rol ax,cl
mov bl,al
and bl,0fh
cmp bl,09h
jng skip2
add bl,07h
skip2:
add bl,30h
mov [rsi],bl
inc rsi
dec ch
jnz again1

disp arr3,04

mov rax,3ch
mov rdi,00
syscall

Program for multiplication of two 8 bit numbers using add and shift method

section .data
msg1 db "enter first 8 bit hex no:",10
len1: equ $-msg1
msg2 db "enter second 8 bit hex no:",10
len2: equ $-msg2
msg3 db "Multiplication of two hex no is:",10
len3: equ $-msg3

section .bss
arr1 resb 3
arr2 resb 3
arr3 resb 4

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

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

section .text
global _start
_start:

disp msg1,len1
inn arr1,03

disp msg2,len2
inn arr2,03

mov rsi,arr1
mov cl,04
xor bx,bx
mov ch,02
up:
cmp byte[rsi],39h
jng sk
sub byte[rsi],07h
sk:
sub byte[rsi],30h
shl bx,cl
add  bl,[rsi]
inc rsi
dec ch
jnz up

xor dx,dx
mov rsi,arr2
mov cl,04
mov ch,02
up1:
cmp byte[rsi],39h
jng sk1
sub byte[rsi],07h
sk1:
sub byte[rsi],30h
shl dx,cl
add dl,[rsi]

inc rsi
dec ch
jnz up1




xor ax,ax
mov cl,00h
mov ch,08h
again:
shr dl,01
jnc xx
shl bx,cl
add ax,bx
shr bx,cl
xx:
inc cl
dec ch
jnz again


mov rsi,arr3
mov ch,04
mov cl,04
again1:
rol ax,cl
mov bl,al
and bl,0fh
cmp bl,09h
jng skip2
add bl,07h
skip2:
add bl,30h
mov [rsi],bl
inc rsi
dec ch
jnz again1

disp arr3,04

mov rax,3ch
mov rdi,00
syscall


No comments:

Post a Comment