fork download
  1. section .data
  2. prompt1 db "Enter the first number: $"
  3. prompt2 db "Enter the second number: $"
  4. prompt3 db "Enter the operation (+, -, *, /): $"
  5. result_msg db "Result: $"
  6.  
  7. num1_buffer times 10 db 0
  8. num2_buffer times 10 db 0
  9. operator_buffer times 2 db 0
  10.  
  11. result_buffer times 10 db 0 ; Reserve space for the result string
  12. result_length equ $-result_buffer ; Calculate the length of the result buffer
  13.  
  14. section .text
  15. global _start
  16.  
  17. _start:
  18. ; Prompt for the first number
  19. mov eax, 4
  20. mov ebx, 1
  21. mov ecx, prompt1
  22. mov edx, 22 ; Length of the prompt1 string
  23. int 80h
  24.  
  25. ; Read the first number
  26. mov eax, 3
  27. mov ebx, 0
  28. mov ecx, num1_buffer
  29. mov edx, 10
  30. int 80h
  31.  
  32. ; ... (Similar code for the second number and operator)
  33.  
  34. ; Parse the input strings to numbers and store them in registers
  35. ; ...
  36.  
  37. ; Perform the calculation based on the operator
  38. ; ...
  39.  
  40. ; Convert the result to a string and store it in a buffer
  41. ; ...
  42.  
  43. ; Display the result
  44. mov eax, 4
  45. mov ebx, 1
  46. mov ecx, result_msg
  47. mov edx, 9 ; Length of the result message
  48. int 80h
  49.  
  50. ; Display the calculated result
  51. mov eax, 4
  52. mov ebx, 1
  53. mov ecx, result_buffer ; Pointer to the result string
  54. mov edx, result_length ; Length of the result string
  55. int 80h
  56.  
  57. ; Exit the program
  58. mov eax, 1
  59. mov ebx, 0
  60. int 80h
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Enter the first numberResult: $