120 lines
1.6 KiB
NASM
120 lines
1.6 KiB
NASM
; THIS CODE HAS NOT BEEN TESTED AND IS NOT FULLY OPERATIONAL.
|
|
|
|
; Problem Statement: Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. Using successive addition method. (Use of 64-bit registers is expected).
|
|
|
|
; 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
|
|
|
|
%macro accept 2
|
|
mov rax,0
|
|
mov rdi,0
|
|
mov rsi,%1
|
|
mov rdx,%2
|
|
syscall
|
|
%endmacro
|
|
|
|
section .data
|
|
|
|
m1 db 10,"----- Multiplication using successive addition -----",10,13
|
|
l1 equ $-m1
|
|
|
|
m2 db 10,"Enter the multiplicand",10,13
|
|
l2 equ $-m2
|
|
|
|
m3 db 10,"Enter the multiplier",10,13
|
|
l3 equ $-m3
|
|
|
|
res db 10,"Multiplication of the numbers is::",10,13
|
|
rlen equ $-res
|
|
|
|
|
|
section .bss
|
|
|
|
numascii resb 03
|
|
mplier resq 02
|
|
mcand resq 02
|
|
;result resq 01
|
|
dispbuff resb 04
|
|
|
|
section .txt
|
|
global _start:
|
|
_start:
|
|
|
|
print m1,l1
|
|
|
|
print m2,l2
|
|
accept numascii,3
|
|
call packnum
|
|
mov byte[mcand],bl
|
|
|
|
print m3,l3
|
|
accept numascii,3
|
|
call packnum
|
|
mov byte[mplier],bl
|
|
|
|
print res,rlen
|
|
|
|
mov rax,0
|
|
cmp qword[mplier],0
|
|
jz ll5
|
|
|
|
ll1:
|
|
add rax,qword[mcand]
|
|
dec qword[mplier]
|
|
jnz ll1
|
|
|
|
ll5:
|
|
call dispnum
|
|
|
|
exit:
|
|
mov rax,60
|
|
mov rbx,00
|
|
syscall
|
|
|
|
|
|
dispnum:
|
|
mov rbx,rax
|
|
mov rcx,04
|
|
mov rdi,dispbuff
|
|
up2:
|
|
rol bx,4
|
|
mov al,bl
|
|
and al,0fh
|
|
cmp al,09
|
|
jbe dskip
|
|
add al,07h
|
|
dskip:
|
|
add al,30h
|
|
mov [rdi],al
|
|
inc rdi
|
|
loop up2
|
|
print dispbuff,4
|
|
ret
|
|
|
|
|
|
packnum:
|
|
mov bl,0
|
|
mov rcx,2
|
|
mov rsi,numascii
|
|
up1:
|
|
rol bl,04
|
|
mov al,[rsi]
|
|
cmp al,39h
|
|
jbe skip1
|
|
sub al,07h
|
|
skip1:
|
|
sub al,30h
|
|
add bl,al
|
|
inc rsi
|
|
loop up1
|
|
ret
|