0% found this document useful (0 votes)
6 views

mpl9

The document is an assembly language program that implements two methods for multiplying two-digit numbers: Successive Addition and Add and Shift. It includes sections for data, uninitialized data, and code, along with system calls for input and output. The program prompts the user for a choice of multiplication method, reads two numbers, performs the multiplication, and displays the result.

Uploaded by

j7203556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

mpl9

The document is an assembly language program that implements two methods for multiplying two-digit numbers: Successive Addition and Add and Shift. It includes sections for data, uninitialized data, and code, along with system calls for input and output. The program prompts the user for a choice of multiplication method, reads two numbers, performs the multiplication, and displays the result.

Uploaded by

j7203556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

section .

data

msg db 'Enter two digit Number::',0xa


msg_len equ $-msg
res db 10,'Multiplication of elements is:: '
res_len equ $-res
choice db 'Enter your Choice:',0xa
db '1.Successive Addition',0xa
db '2.Add and Shift method',0xa
db '3.Exit',0xa
choice_len equ $-choice

section .bss
num resb 03
num1 resb 01
result resb 04
cho resb 2

section .text

global _start
_start:

xor rax, rax


xor rbx, rbx
xor rcx, rcx
xor rdx, rdx
mov byte [result], 0
mov byte [num], 0
mov byte [num1], 0

; Display menu
mov rax, 1
mov rdi, 1
mov rsi, choice
mov rdx, choice_len
syscall

; Read user choice


mov rax, 0
mov rdi, 0
mov rsi, cho
mov rdx, 2
syscall

cmp byte [cho], 31h ; If choice == '1'


je a

cmp byte [cho], 32h ; If choice == '2'


je b

jmp exit

a:
call Succe_addition
jmp _start

b:
call Add_shift
jmp _start

exit:
mov rax, 60
mov rdi, 0
syscall

; ASCII to Hex conversion


convert:
xor rbx, rbx
xor rcx, rcx
xor rax, rax

mov rcx, 02
mov rsi, num
up1:
rol bl, 04
mov al, [rsi]
cmp al, 39h
jbe p1
sub al, 07h
jmp p2
p1:
sub al, 30h
p2:
add bl, al
inc rsi
loop up1
ret

; Hex to ASCII conversion and display


display:
mov rcx, 4
mov rdi, result
dup1:
rol bx, 4
mov al, bl
and al, 0fh
cmp al, 09h
jbe p3
add al, 07h
jmp p4
p3:
add al, 30h
p4:
mov [rdi], al
inc rdi
loop dup1

mov rax, 1
mov rdi, 1
mov rsi, result
mov rdx, 4
syscall
ret

; Successive Addition Method


Succe_addition:

; Get first number


mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, msg_len
syscall

mov rax, 0
mov rdi, 0
mov rsi, num
mov rdx, 3
syscall

call convert
mov [num1], bl ; Store first number

; Get second number


mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, msg_len
syscall

mov rax, 0
mov rdi, 0
mov rsi, num
mov rdx, 3
syscall

call convert
xor rcx, rcx
xor rax, rax
mov rax, [num1] ; First number

repet:
add rcx, rax ; Add first number to sum
dec bl
jnz repet ; Loop until second number is exhausted

mov [result], rcx ; Store full result properly

; Display multiplication result


mov rax, 1
mov rdi, 1
mov rsi, res
mov rdx, res_len
syscall

mov rbx, [result]


call display
ret

; Add and Shift Multiplication Method


Add_shift:

; Get first number


mov rax, 1
mov rdi, 1

You might also like