fork download
  1. section .data
  2. prompt_b db 'Enter the value of b: ', 0
  3. prompt_c db 'Enter the value of c: ', 0
  4. prompt_d db 'Enter the value of d: ', 0
  5. result_msg db 'Result: ', 0
  6.  
  7. section .bss
  8. b resd 1
  9. c resd 1
  10. d resd 1
  11. result resd 1
  12.  
  13. section .text
  14. global _start
  15.  
  16. _start:
  17. ; Prompt user for input b
  18. mov eax, 4
  19. mov ebx, 1
  20. mov ecx, prompt_b
  21. mov edx, 21
  22. int 0x80
  23.  
  24. ; Read input b
  25. mov eax, 3
  26. mov ebx, 0
  27. mov ecx, b
  28. mov edx, 4
  29. int 0x80
  30.  
  31. ; Prompt user for input c
  32. mov eax, 4
  33. mov ebx, 1
  34. mov ecx, prompt_c
  35. mov edx, 21
  36. int 0x80
  37.  
  38. ; Read input c
  39. mov eax, 3
  40. mov ebx, 0
  41. mov ecx, c
  42. mov edx, 4
  43. int 0x80
  44.  
  45. ; Prompt user for input d
  46. mov eax, 4
  47. mov ebx, 1
  48. mov ecx, prompt_d
  49. mov edx, 21
  50. int 0x80
  51.  
  52. ; Read input d
  53. mov eax, 3
  54. mov ebx, 0
  55. mov ecx, d
  56. mov edx, 4
  57. int 0x80
  58.  
  59. ; Convert input to integers
  60. mov eax, [b]
  61. sub eax, '0'
  62. mov [b], eax
  63.  
  64. mov eax, [c]
  65. sub eax, '0'
  66. mov [c], eax
  67.  
  68. mov eax, [d]
  69. sub eax, '0'
  70. mov [d], eax
  71.  
  72. ; Calculate expression: 3b - 12c/d
  73. mov eax, [b] ; eax = b
  74. imul eax, 3 ; eax = 3b
  75.  
  76. mov ebx, [c] ; ebx = c
  77. imul ebx, 12 ; ebx = 12c
  78.  
  79. mov ecx, [d] ; ecx = d
  80. idiv ecx ; eax = 12c/d
  81.  
  82. sub eax, ebx ; eax = 3b - 12c/d
  83.  
  84. mov [result], eax
  85.  
  86. ; Display result
  87. mov eax, 4
  88. mov ebx, 1
  89. mov ecx, result_msg
  90. mov edx, 8
  91. int 0x80
  92.  
  93. mov eax, 4
  94. mov ebx, 1
  95. mov ecx, [result]
  96. mov edx, 4
  97. int 0x80
  98.  
  99. ; Exit
  100. mov eax, 1
  101. xor ebx, ebx
  102. int 0x80
  103.  
Success #stdin #stdout 0.02s 5308KB
stdin
Standard input is empty
stdout
Enter the value of b:Enter the value of c:Enter the value of d:Result: