Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code is for NASM Assembly language . I have attached the assignment , output examples , and my code that doesn't seem to

The following code is for NASM Assembly language. I have attached the assignment, output examples, and my code that doesn't seem to work.

I am having a problem with the ebx variable, where it becomes 10 no matter what my input actually was.

image text in transcribed

Here is my code below, which has a problem with the ebx variable being automatically changed to 10 no matter what the user inputs. I have only coded the multiplication part, which is where ebx is used to multiply the variable eax. The variable eax is where user input is automatically stored. CODE STARTS HERE is where my code starts.

segment .data

segment .bss

segment .text

global asm_main

asm_main:

push ebp

mov ebp, esp

; ********** CODE STARTS HERE **********

start:

call read_int

mov ebx, eax

call read_char

mov ecx, eax

call read_int

mov esi, eax

cmp ecx,'+'

JE add_loop

cmp ecx,'-'

JE sub_loop

cmp ecx,'*'

JE multi_loop

cmp ecx,'/'

JE div_loop

cmp ecx,'%'

JE mod_loop

add_loop:

JMP start

sub_loop:

JMP start

multi_loop:

imul ebx

call print_int

JMP stop

div_loop:

JMP start

mod_loop:

JMP start

stop:

; *********** CODE ENDS HERE ***********

mov eax, 0

mov esp, ebp

pop ebp

ret

My program output below:

image text in transcribed

Assignment: Calculator Description: Write a calculator program in assembly. It should handle the following functions: addition (+), subtraction (-), multiplication (*), integer division (), modulo division (%), and exponentiation(. Your program should 1. Read an integer from the user 2. Read a character from the user, representing the function. (+,-, *J, % 3. Read another integer from the user 4. Print an equals sign () 5. Print the result Plcase comment your code, and format it so that it looks clean! (examples on next page) Output Examples: andrew@dev:/calculator$ ./calculator 17 - This is input - This is input - This is input -This is output - This is output 28 andrew@de/calculator$ ./calculator 25 74 andrew@dev:/calculator$ ./calculator 10 110 andrew@dev: /calculator$ ./calculator 67 andrew@dev:/calculator$./calculator 67 andrew@dev:/calculator$ ./calculator 64

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions