Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. ; aufgabenteil b
  2. SECTION .data
  3. message1: db "Choose mode: (SUB = 0; ADD = 1; MUL = 2)): ", 0
  4. message2: db "Enter first number: ", 0
  5. message3: db "Enter second number: ", 0
  6. message4: db "Illegal mode", 0
  7. formatin: db "%d", 0
  8. formatout: db "%d", 10, 0
  9. mode: times 4 db 0 ; mode
  10. integer1: times 4 db 0 ; a
  11. integer2: times 4 db 0 ; b
  12.  
  13. SECTION .text
  14. global _start
  15. global _add
  16. global _sub
  17. global _mul
  18. global _exit
  19. extern scanf
  20. extern printf
  21.  
  22. _start:
  23.  
  24. push ebx
  25. push ecx
  26. push eax
  27.  
  28. push message1
  29. call printf
  30. add esp, 4
  31. push mode
  32. push formatin
  33. call scanf
  34. add esp, 8
  35.  
  36.  
  37. push message2
  38. call printf
  39. add esp, 4
  40. push integer1
  41. push formatin
  42. call scanf
  43. add esp, 8
  44.  
  45. push message3
  46. call printf
  47. add esp, 4
  48. push integer2
  49. push formatin
  50. call scanf
  51. add esp, 8
  52.  
  53. ;in register schreiben
  54. mov eax, dword [integer1]
  55. mov ebx, dword [integer2]
  56. mov ecx, dword [mode]
  57.  
  58. cmp ecx, 0
  59. je _sub
  60. cmp ecx, 1
  61. je _add
  62. cmp ecx, 2
  63. je _mul
  64. cmp ecx, 3
  65. jge _exit
  66.  
  67. ret
  68.  
  69.  
  70. _add:
  71. add eax, ebx
  72. push eax
  73. push formatout
  74. call printf
  75. add esp, 8
  76.  
  77.  
  78. pop ebx
  79. pop ecx
  80. pop eax
  81. mov eax, 0
  82. ret
  83.  
  84. _sub:
  85. sub eax, ebx
  86. push eax
  87. push formatout
  88. call printf
  89. add esp, 8
  90.  
  91.  
  92. pop ebx
  93. pop ecx
  94. pop eax
  95. mov eax, 0
  96. ret
  97.  
  98. _mul:
  99. mul ebx
  100. push eax
  101. push formatout
  102. call printf
  103. add esp, 8
  104.  
  105.  
  106. pop ebx
  107. pop ecx
  108. pop eax
  109. mov eax, 0
  110. ret
  111.  
  112. _exit:
  113. push message4
  114. call printf
  115. add esp, 4
  116. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement