I'm working in assembly using nasm, and need to create a program that performs simple calculations. The prompt is below:
Write a program that contains 4 procedures:
ADD
SUBTRACT
MULTIPLY
DIVIDE
Read expressions from the user, such as:
1 + 2
4 - 3
2 * 3
4 / 2
.
Execute every expression by calling the proper procedure.
The end of user input is a period: .
The output for the above code should be:
1 + 2 = 3
4 - 3 = 1
2 * 3 = 6
4 / 2 = 2
=============== nasm assembly code for above function is=========================
;;;; declaring the frequently used number
SYS_EXIT equ 1
SYS_READ equ 3
SYS_WRITE equ 4
STDIN equ 0
STDOUT equ 1
segment .data
;;; declaring the messages and their length
msg1 db "Enter a digit: ", 0xA,0xD
len1 equ $- msg1
msg2 db "Please enter a second digit:",
0xA,0xD
len2 equ $- msg2
msg3 db "The sum is: "
len3 equ $- msg3
msg4 db "The subtraction is :"
len4 equ $- msg4
msg5 db "The multiply is:"
len5 equ $- msg5
msg6 db "The division is:"
len6 equ $- msg6
segment .bss
num1 resb 2 ;holds 2 byte number
num2 resb 2 ;same as above
res resb 1 ;holds one byte number
section .text
global _start ;global start for gcc
_start: ;entry point for the linker
;;;;;;;;;; addition
;;;;; printing to enter a number
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg1
mov edx, len1
int 0x80
;;;;;;;;; reading first number
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num1
mov edx, 2
int 0x80
;;;;;;;; printing message to enter second number
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg2
mov edx, len2
int 0x80
;;;;;;;;;;reading second number
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num2
mov edx, 2
int 0x80
;;;;;;;;;;writing about result
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg3
mov edx, len3
int 0x80
;;;;;;;; calculation from here
mov eax, [num1]
sub eax, '0'
mov ebx, [num2]
sub ebx, '0'
add eax, ebx
add eax, '0'
mov [res], eax
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, res
mov edx, 1
int 0x80
;;;;;;;;;;;;;;; subtraction ;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg1
mov edx, len1
int 0x80
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num1
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg2
mov edx, len2
int 0x80
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num2
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg4
mov edx, len4
int 0x80
mov eax, [num1]
sub eax, '0'
mov ebx, [num2]
sub ebx, '0'
sub eax, ebx
add eax, '0'
mov [res], eax
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, res
mov edx, 1
int 0x80
;;;;;;;;;;;;;;;;;;;;;;;;;;;; multiplication
;;;;;;;;;;;;;;;;;;;;;
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg1
mov edx, len1
int 0x80
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num1
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg2
mov edx, len2
int 0x80
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num2
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg5
mov edx, len5
int 0x80
mov al, [num1]
sub al, '0'
mov bl, [num2]
sub bl, '0'
mul bl
add al, '0'
mov [res], al
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, res
mov edx, 1
int 0x80
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; division
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg1
mov edx, len1
int 0x80
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num1
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg2
mov edx, len2
int 0x80
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num2
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg6
mov edx, len6
int 0x80
mov ax, [num1]
sub ax, '0'
mov bl, [num2]
sub bl, '0'
div bl
add ax, '0'
mov [res], ax
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, res
mov edx, 1
int 0x80
exit:
mov eax, SYS_EXIT
xor ebx, ebx
int 0x80
----------------------------------------------------------- end ------------------------------------------------------------------------------------
Screenshots of the question and the output
------------------------------------------------------------------------------------------------------------------------------------------------------
=============================end====================================================
************************************* PLEASE LIKE THE POST ********************************************************
I'm working in assembly using nasm, and need to create a program that performs simple calculations....
Write MIPS code that emulates a simple calculator. The calculator initially has the value 0. Prompt the user to enter a command. A command is a number, where 0 is add, 1 is subtract, 2 is multiply, 3 is divide, 4 is clear, and 5 is exit. When the user enters 0, 1, 2, or 3, prompt the user for a number to add, subtract, multiply or divide from the current value. If the user enters 4, then clear the...
Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit . Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Please answer in python and make it simple. Please implement proper indentation, not just...
Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into an array; reverse the array and display the reversed array. .data arrayInt DWORD 10 DUP(?) Your program consists of 4 procedures: 1. main procedure: call procedures getInput, reverseArray, displayArray 2. getInput procedure: prompt user to enter 10 integer numbers, save the numbers into the memory for the arrayInt 3. reverseArray: reverse arrayInt 4. displayArray: display the reversed array
The main method of your calculator program has started to get a little messy. In this assignment, you will clean it up some by moving some of your code into new methods. Methods allow you to organize your code, avoid repetition, and make aspects of your code easier to modify. While the calculator program is very simple, this assignment attempts to show you how larger, real world programs are structured. As a new programmer in a job, you will likely...
CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...
NEED HELP WITH THIS . Write a MARIE assembly language program that would simulate calling and executing the following C function, as shown below: z = someFunction(a, b); where z, a and b are main( ) program variables, and the values stored in a and b are input by the user. The value stored in z will be output. Did your program execute correctly? This is the code for the function: int someFunction(int x, int y) { return 3 *...
Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...
I need help with this program. It is in Irvine MASM Assembly Language. You are to write a program to compute the results of a postfix expression. The expression has the format operand operand operator where the operator can be +, -, *. You must use a stack to evaluate the expressions. (The system Stack will not work.) Print out the input expression and the results of the evaluation. Read the data from a file and output to a file....
Question 20: Write a python program that will perform the operations of simple calculator. The operations are : Addition, subtraction, Multiplication and division. Sample output : Select operation. 1.Add 2.Subtract 3.Multiply 4.Divide Enter choice(1/2/3/4): 3 Enter first number: 15 Enter second number: 14 15 * 14 = 210
I need to create a bit of code for javascript which I can have random numbers generate with a certain amount of digits set by the user. and ask the user how many times they want this to happen. For example The user says they want a number with 4 digits (any number between 0 - 9999) and the user can input if they want to add, subtract, multiply, divide, or make it random 2 random numbers are generated. First...