Oh boy... Where do I even begin? I have tried COUNTLESS times to get a simple program that calculates the surface area of a box (in only 4 or less multiplication steps) and returns the total area. I have tried defining the program with the main variables being words, and then again being bytes. but no matter what, I keep getting an answer that does not match up. my program contains no errors or warnings, so that is a good sign so far. I've tried signed and unsigned multiplication, but nothing seems to quite work. I can't use double words unfortunately as I do not have the right software the following is my program:
INCLUDE io.h
Cr EQU 0DH ; carriage return
Lf EQU 0AH ; line feed
TheStack SEGMENT STACK
DW 100H DUP (?)
TheStack ENDS
Data SEGMENT
a Dw ?
b Dw ?
c Dw ?
d Dw ?
f Dw ?
g Dw ?
h Dw ?
e dw '2'
Int1 db 6 DUP (?), 0
Int2 db 6 DUP (?), 0
SUM Db 6 DUP (?), 0
Int3 Db 6 DUP (?), 0
Prompt1 DB 'Please enter the height: ', 0
Prompt2 DB Cr, Lf, 'Enter the width: ', 0
Prompt3 DB Cr, Lf, 'Enter the length: ', 0
String DB 40 DUP (?)
Label1 DB Cr, Lf, 'The sum is '
result1 DB 10 DUP (?), 0
Data ENDS
Code SEGMENT
ASSUME Cs:Code, Ds:Data
Start: Mov Ax, SEG Data ; Load Data Segment Number.
Mov Ds, Ax
Prompt: Output Prompt1 ; Prompt for first number.
Inputs String, 40 ; Read the ASCII characters.
AToI String ; Convert ASCII to Integer.
Mov a, ax; Store first number.
Output Prompt2 ; Prompt for second number.
Inputs String, 40
AToI String
Mov b, dx ; Store second number.
Mul dx; Add second number.
mov d, ax
itoa result1, ax
output result1
Output Prompt3
Inputs String, 40
AToI String
Mov c, Dx ; Store second number
Mul dx; Add second number.
mov f, dx
output f
Mov b, dx
Mov c, ax
mul dx
mov g, ax
ATOI g
mov g, ax
ATOI f
mov f, ax
ATOI d
mov d, ax
add ax, f
add ax, g
mov h, ax
output h
AToI e
mov e, ax
mov h, dx
mul dx
itoa result1, ax
output result1
Quit: Mov Al, 0 ; Put return code of zero in Al.
Mov Ah, 4CH ; Put DOS function call in Ah.
int 21H ; Call DOS
Code ENDS
END Start
I do apologize for the bad explanations in the code as I've copied the jist of it from previous program. now what I don't understand is how some perfectly defined variables can return incorrect values. I've even changed variables around, but I still have not had luck. This is both confusing, and annoying. To put it in perspective, when I try to multiply 1 times 1, the returned value is 402, which is way off! I am new to programming in assembly, so I do believe that part of this is due to inexperience. My question is how does this error free program end up returning wrong values when it is seemingly put together correctly and checked over numerous times for errors? Is there a missing piece? Do I need to re-write it entirely? Is it the emulator's fault? What is it that is wrong with the code that causes what seems like a perfect program to not work right?