Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following program, which has the formula of: ( b + c * b - a / 4 ) / ( a *

I have the following program, which has the formula of: (b + c*b - a/4)/(a*b -1)
However, when I run it it gives me different results that it should be what might be the cause, can you help me to provide me updated version, will really appreciate it.
The program:
.486
.model flat, stdcall
option casemap: none
include \masm32\include\windows.inc ; For a management by the modes of Window
include \masm32\include\user32.inc ; For using MessageBox
include \masm32\include\kernel32.inc ; For using ExitProcess
include \masm32\include\masm32.inc ; For using FloatToStr
includelib \masm32\lib\user32.lib ; For using MessageBox
includelib \masm32\lib\kernel32.lib ; For using ExitProcess
include Ext_macros.inc
NUM macro Q, M, N
MOV AL, M ; Copy number B to register AL
CBW ; Extension AL to AX
MOV BL,4 ; Copy constant "4" to register BL
IDIV BL ; Division register AX, as variable "B" on constant "4", quotient in AL
ADD AL, N ; Addition register AL and "C", as "C+B/4"
SUB AL,33 ; Subtraction from register AL constant "33", as "C+B/4-33"
CBW ; Extension AL to AX
MOV Q, AX ; Copy value of numerator from registry AX to registry BX
endm
DEN macro R, X, Y, Z
MOV AL, X ; Copy number A to register AL
MOV CL, Z ; Copy number C to register CL
IMUL CL ; Multiplication register AL and "A" on registry CL (variable C), result in AX
MOV CH, Y ; Copy number B to register CH
IDIV CH ; Division register AX, as result "A*C" on variable "B", quotient in AL
MOV DL,1 ; Copy constant "1" to register DL
SUB AL, DL ; Subtraction from register AL constant "1", as "A*C/B-1"
MOV R, AL ; Copy value of denominator from registry AL to registry R
endm
.data
msg_title db "Lab 5",0
buffer db 256 dup(?)
format db "A =%d",10,"B =%d",10,"C =%d",10,"(C -33+ B/4)/(A*C/B -1)=%d",0
msg_title0 db "WARNING!", 0 ; text variable for title of window
msg_message db "Value in denominator equal 0",0 ; text variable for text in window
A DB -2,-6,2,48,-6,2
B DB 8,12,8,48,4,-4
C0 DB 16,14,40,-3,-2,-2
D dd 0
E dd 0
F dd 0
.code
start:
MOV EDI, 0 ; Initialize pointer to array index
CYCLE:
; Calculate numerator
NUM BX, B[EDI], C0[EDI]
; Calculate denominator
DEN AL, A[EDI], B[EDI], C0[EDI]
; Check if denominator is zero
CMP AL,0
JZ ZERO
; Calculate the expression
MOV DL, AL
MOV AX, BX
IDIV DL
; Check if result is even or odd
TEST AL,1
JNZ ODD
; If result is even, divide by 2
SAR AL,1
JMP CONT
ODD:
; If result is odd, multiply by 5
MOV BH,5
IMUL BH
CONT:
; Prepare for displaying the message box
CWDE
movsx ESI, A[EDI]
mov D, ESI
movsx ESI, B[EDI]
mov E, ESI
movsx ESI, C0[EDI]
mov F, ESI
invoke wsprintf, addr buffer, addr format, D, E, F, eax
invoke MessageBox, 0, addr buffer, addr msg_title, MB_OK
jmp PR_CONT
ZERO:
; Display warning message if denominator is zero
invoke MessageBox, 0, addr msg_message, addr msg_title0, MB_OK
PR_CONT:
INC EDI
CMP EDI, 6 ; Check if all values have been processed
JL CYCLE ; If not, continue with the next value
; Exit the program
invoke ExitProcess, 0
end start

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions