Professional Documents
Culture Documents
MP Ass4
MP Ass4
Use
successive addition and add and shift method. (use of 64-bit registers is expected)
%macro accept 2
mov rax,3
mov rcx,%1
mov rdx,%2
int 80h
%endmacro
section .data
msgmenu db 10,"******************MENU*******************",10
db 10,"1).Succesive addition",10
db 10,"2).Exit",10
db 10,"Enter your choice: ",10
section .bss
acii1 resb 3
acii1len equ $-acii1
acii2 resb 3
acii2len equ $-acii2
multi1 resb 1
multi2 resb 1
resl resb 1
resh resb 1
dispnum resb 4
displen equ $-dispnum
choice resb 2
choice_len:equ $-choice
section .text
global _start:
_start:
menu:
dispmsg msgmenu,menulen
accept choice,choice_len
case1:
cmp byte[choice],'1'
jne case2
dispmsg msg1,msg1len
accept acii1,3
mov rsi,acii1
call accept8
mov [multi1],bl
dispmsg msg2,msg2len
accept acii2,3
mov rsi,acii2
call accept8
mov [multi2],bl
xor rax,rax
xor rcx,rcx
mov al,[multi1]
mov bl,[multi2]
mov rdx,00
addup:
add ecx,eax
dec bl
jnz addup
mov eax,ecx
call display
case2:
cmp byte[choice],'3'
je ext
jmp menu
ext:
mov rax,1
mov rbx,0
int 80h
accept8:
xor rbx,rbx
mov rcx,02
display:
mov rsi,dispnum+3
mov rcx,4
xor rbx,rbx
cnt: mov rdx,0
mov rbx,16
div rbx
cmp dl, 09h
jbe add30
add dl, 07h
add30:
add dl,30h
mov [rsi],dl
dec rsi
dec rcx
jnz cnt
dispmsg dispnum,4
************** OUTPUT**********************
******************MENU*******************
1).Succesive addition
2).Exit
Title:
Add & Shift Method
%macro dispmsg 2
mov rax,4
mov rbx,1
mov rcx,%1
mov rdx,%2
int 80h
%endmacro
%macro accept 2
mov rax,3
mov rbx,1
mov rcx,%1
mov rdx,%2
int 80h
%endmacro
section .data
msgmenu db 10,"******************MENU*******************",10
db 10,"1)shift & add",10
db 10,"2).Exit",10
db 10,"Enter your choice: ",10
menulen equ $-msgmenu
section .bss
acii1 resb 3
acii1len equ $-acii1
acii2 resb 3
acii2len equ $-acii2
multi1 resb 1
multi2 resb 1
resl resb 1
resh resb 1
dispnum resb 4
displen equ $-dispnum
choice resb 2
choice_len:equ $-choice
section .text
global _start:
_start:
menu:
dispmsg msgmenu,menulen
accept choice,choice_len
case1:
cmp byte[choice],'1' ;compare choice
jne case2
dispmsg msg1,msg1len ;display msg
accept acii1,3
mov rsi,acii1 ;move ascii to rsi
call accept8 ;call to accept8
mov [multi1],bl ;point bl to 2nd no.
ad:
rcr al,01 ;raotate al reg. with 01 carry to right
jnc next1
mov bh,00h ;clear bh reg.
shl bx,cl ;shift left cl to bx
add [resl],bx ;add bx to resl
mov bl,[multi2] ;mov no.2 into bl
next1:
inc cl ;increament cl reg.
dec edx ;decreament edx reg.
jnz ad ;jump if not zero back to ad
mov ax,[resl] ;mov content of resl to al reg.
call display ;call to display
case2:
cmp byte[choice],'2' ;compare choice
je exit ;jump if equql to exit
jmp menu ;jump back to menu
exit:
mov rax,1 ;mov 01 to rax
mov rbx,0 ;mov 0 to rbx
int 80h ;call int 80h
L12:
shl bx,4 ;shift left bx with 4bit
mov al,[rsi] ;mov content of rsi to al
cmp al,39h ;compare al with 39
jbe sub30
sub al,7h ;substract al by 7
display:
mov rsi,dispnum+3 ; load last byte address of char_ans in rsi
mov rcx,4 ; number of digits
xor rbx,rbx
cnt:
mov rdx,0
mov rbx,16
div rbx
cmp dl, 09h ; check for remainder in RDX
jbe add30
add dl, 07h
add30:
add dl,30h ; calculate ASCII code
mov [rsi],dl ; store it in buffer
dec rsi ; point to one byte back
******************* OUTPUT***********************
******************MENU*******************
2).Exit