fork download
  1. section .data
  2. msg db 10,"Menu"
  3. db 10,"1.Succesive addition"
  4. db 10,'2.Add and Shift Addition'
  5. db 10,"3.Exit"
  6. db 10,"Enter your choice: "
  7. len equ $-msg
  8. msg1 db 10,"Enter 1st two digit number:"
  9. len1 equ $-msg1
  10. msg2 db 10,"Enter 2nd two digit number:"
  11. len2 equ $-msg2
  12. msg3 db 10,"Result:"
  13. len3 equ $-msg
  14. section .bss
  15. numascii resb 05
  16. num1 resb 05
  17. num2 resb 05
  18. dispbuff resb 05
  19. %macro print 2
  20. mov rax,1
  21. mov rdi,1
  22. mov rsi,%1
  23. mov rdx,%2
  24. syscall
  25. %endmacro
  26. %macro accept 2
  27. mov rax,0
  28. mov rdi,0
  29. mov rsi,%1
  30. mov rdx,%2
  31. syscall
  32. %endmacro
  33. section .text
  34. global _start
  35. _start:
  36. print msg,len
  37. accept numascii,2
  38. case1:
  39. cmp byte[numascii],'1'
  40. jne case2
  41. call proc
  42. jmp _start
  43. case2:
  44. cmp byte[numascii],'2'
  45. jne exit
  46. call multi
  47. jmp _start
  48. mov rax,60
  49. syscall
  50. ;successive addition method
  51. proc:
  52. print msg1,len1 ;enter 1st number
  53. accept numascii,3
  54. call packnum
  55. mov [num1],bl ;num1= 02
  56. print msg2,len2 ;enter 2nd number
  57. accept numascii,3
  58. call packnum ; bl = 03
  59. mov ax,0 ; ax=0
  60. up:
  61. add ax,[num1] ; ax= ax+[num1] = 04 + 02 = 06
  62. dec bl ; bl=0
  63. jnz up
  64. mov bx,ax ; bx=06
  65. call dispnum
  66. ret
  67. ; Add & Shift method
  68. multi:
  69. print msg1,len1
  70. accept numascii,3
  71. call packnum
  72. mov [num1],bl ; num1=02
  73. print msg2,len2
  74. accept numascii,3
  75. call packnum
  76. mov [num2],bl ; num2=03
  77. mov ax,00h
  78. mov dx,00h
  79. mov al,[num1] ; al= 02 0000 0010
  80. mov bl,[num2] ; bl = 03 0000 0011
  81. mov cx,00h ;result
  82. mov dl,08h ;counter
  83. l2:
  84. shr bl,01h ; bl= 0000 0000 , shr = 0000 0000 0
  85. jnc l1
  86. add cx,ax ; cx=cx+ax= 02+04 = 06
  87. l1: shl al,01 ;al= 0000 1000, shl= 0001 0000
  88. dec dl ; dl=05
  89. jnz l2
  90. mov rbx,rcx
  91. call dispnum
  92. ret
  93. dispnum:
  94. mov rcx,04
  95. mov edi,dispbuff
  96. up2:
  97. rol bx,04
  98. mov al,bl
  99. and al,0fh
  100. cmp al,09h
  101. jbe skip
  102. add al,07h
  103. skip:
  104. add al,30h
  105. mov [edi],al
  106. inc edi
  107. loop up2
  108. print dispbuff,4
  109. ret
  110. packnum:
  111. mov bx,0
  112. mov rcx,02
  113. mov esi,numascii
  114. up1:rol bl,04
  115. mov al,[esi]
  116. cmp al,39h
  117. jbe skip1
  118. sub al,07h
  119. skip1:
  120. sub al,30h
  121. add bl,al
  122. inc esi
  123. loop up1
  124. ret
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Menu
1.Succesive addition
2.Add and Shift Addition
3.Exit
Enter your choice: