Assignment No. 6

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)

;——————————p5.asm————————————————
%macro dispmsg 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro accept 2
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .data

msg db 10,’Enter two digit Number::’
msg_len equ $-msg
res db 10,’Multiplication of elements is::’
res_len equ $-res
choice db 10,13,’Enter your Choice:’
db 10,13,’1.Successive Addition’
db 10,13,’2.Add and Shift method’
db 10,13,’3.Exit’
db 10,13,’Enter choice=’
choice_len equ $-choice

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

section .text

global _start
_start:

mov eax,0
mov ebx,0
mov ecx,0
mov edx,0
mov byte[result],0
mov byte[num],0
mov byte[num1],0

dispmsg choice,choice_len
accept cho,2

cmp byte[cho],31h
je a

cmp byte[cho],32h
je b

jmp exit

a:call Succe_addition

jmp _start

b:call Add_shift

jmp _start

exit:
mov eax,1
int 80h

convert:
mov ebx,0
mov ecx,0
mov eax,0

mov ecx,02
mov esi,num
up1:
rol bl,04
mov al,[esi]
cmp al,39h
jg p1
sub al,30h
jmp p2
p1: sub al,37h
p2:add bl,al
inc esi
loop up1
ret

display:
mov ecx,4
mov edi,result
dup1:
rol bx,4
mov al,bl
and al,0fh
cmp al,09h
jg p3
add al,30h
jmp p4
p3: add al,37h
p4:mov [edi],al
inc edi
loop dup1

dispmsg result,4
ret

Succe_addition:

dispmsg msg,msg_len
accept num,3

call convert
mov [num1],bl

dispmsg msg,msg_len
accept num,3
call convert
mov ecx,0
mov eax,0
mov eax,[num1]

repet:
add ecx,eax
dec bl
jnz repet

mov [result],ecx
dispmsg res,res_len
mov ebx,[result]

call display
ret

Add_shift:

dispmsg msg,msg_len
accept num,3

call convert
mov [num1],bl

dispmsg msg,msg_len
accept num,3
call convert

mov [num],bl

mov ebx,0
mov ecx,0
mov edx,0
mov eax,0
mov dl,08
mov al,[num1]
mov bl,[num]

p11:shr bx,01
jnc p
add cx,ax
p:shl ax,01
dec dl
jnz p11

mov [result],ecx
dispmsg res,res_len
mov ebx,[result]
call display

ret

;——————————————————————————————————————————
Steps to execute the above program is as follows:

dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ nasm -f elf p5.asm
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ ld -m elf_i386 -s -o p5  p5.o
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ ./p5

Enter your Choice:
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=1

Enter two digit Number::05

Enter two digit Number::02

Multiplication of elements is::000A
Enter your Choice:
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=2

Enter two digit Number::05

Enter two digit Number::03

Multiplication of elements is::000F
Enter your Choice:
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=3
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$

Share Button

10 thoughts on “Assignment No. 6

  1. Excellent beat ! I wish to apprentice even aas yyou amend your website, how could i subscribe for a weblog site?

    The account aided me a appropriate deal. I have been a little bit familiar
    of this your broadcast offered shiny cleaar idea

  2. My partner and I stumbled over here by a diffrent page and thought I mayy as
    well chehk things out. I like what I see soo i am just following you.
    Look forward to checking outt your web page again.

  3. Awesome blog! Do you have any hints for aspiring writers?
    I’m hoping to start my own website soon but I’m a little lost on everything.

    Would you propose starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m
    totally confused .. Any recommendations? Thanks!

Leave a Reply to escorts in Dallas Cancel reply

Your email address will not be published. Required fields are marked *