Crazy output. Think I've got some memory problems or something...

Started by Nimue, December 07, 2009, 06:17:48 AM

Previous topic - Next topic

Nimue

Here's the code and here's the output. Been trying to debug this for days with friends. Doesn't make any sense.


Please input a number between 1 and 1024 inclusive.
1000

Please input a number between 256 and 4,000,000 inclusive.
Your number, +100ten to the file read in again and stuff.
+256
Please input a number between 256 and 4,000,000 inclusive.
^C

C:\PROGRA~1\WIRELE~1\EYETOY~1\asm\projects\AS9750~1>



The code:


TITLE FINALASSIGNMENT

INCLUDE Irvine16.inc

;This macro is a generic comparing thinger. To compare if values are smaller or larger.
compare MACRO number1: REQ, number2:REQ, LESSORMORE:REQ
local LESSTHAN,GREATERTHAN,ERRORMESSAGELT,ERRORMESSAGEGT,ENDIT,ERRORS
push ax
push bx
mov eax,number1
mov bh,LESSORMORE
cmp bh,1
je LESSTHAN
cmp bh,0
je GREATERTHAN

LESSTHAN:
cmp eax,number2
jl ERRORS
mov cl,0
jmp ENDIT
GREATERTHAN:
cmp eax,number2
jg ERRORS
mov cl,0
jmp ENDIT

ERRORS:
mov dx, offset errormessage
mov ah,9
int 21h
mov eax,number1
call writeint
cmp bh,1
je ERRORMESSAGELT
cmp bh,0
je ERRORMESSAGEGT

ERRORMESSAGEGT:

mov dx, offset errormessagegt
mov ah,9
int 21h
mov cl,100
mov eax,number2
call writeint
JMP ENDIT
ERRORMESSAGELT:

mov dx, offset errormessagelt
mov ah,9
int 21h
mov cl,100
mov eax,number2
call writeint
jmp ENDIT

ENDIT:
call crlf
pop bx
pop ax
ENDM

numbers struct
num1 DWORD ?
num2 DWORD ?
numbers ENDS


.data
snumber1 numbers <>
snumber2 numbers <>
snumber3 numbers <>
intromessage BYTE "Please input a number between 1 and 1024 inclusive.",0dh,0ah,"$"
intromessage2 BYTE "Please input a number between 256 and 4,000,000 inclusive.",0dh,0ah,"$"
intromessage3 BYTE "Please input a number between 1 and 1024 inclusive.",0dh,0ah,"$"
intromessage4 BYTE "It's 4AM. I want this done. Input a stupid filename to write to. It'll get overwritten, so don't be stupid.",0dh,0ah,"$"
readmsg BYTE "Here are the numbers that were written to the file read in again and stuff.",0dh,0ah,"$"
errormessage BYTE "Your number, ","$"
errormessagelt BYTE "Was less than ","$"
errormessagegt BYTE "Was greater than, ","$"
erroropening BYTE "Error opening the file.","$"
muldivmsg BYTE "Here is the first number multiplied by 1024 and the second divided by 2048",0dh,0ah,"$"
buffer BYTE 100 dup(0)
filehandler WORD ?


.code

_main PROC
mov ax, @data
mov ds, ax
call ClrScr
firstcheck:
mov dx, offset intromessage
mov ah, 9
int 21h
call ReadInt
mov snumber1.num1, eax
compare snumber1.num1, 1, 1
cmp cl,100
je firstcheck
compare snumber1.num1, 1024, 0
cmp cl,100
je firstcheck
secondcheck:
mov dx, offset intromessage2
mov ah, 9
int 21h
call ReadInt
mov snumber1.num2, eax
compare snumber1.num2, 256, 1
cmp cl,100
je secondcheck
compare snumber1.num2,4000000,0
cmp cl,100
je secondcheck
mov ebx,snumber1.num1
mov snumber2.num1,ebx
mov ebx,snumber1.num2
mov snumber2.num2,ebx

shl snumber2.num1,10
shr snumber2.num2,11
mov dx, offset muldivmsg
mov ah,9
int 21h
mov eax,snumber2.num1
call writeint
call crlf
mov eax,snumber2.num2
call writeint
call crlf
mov dx,offset intromessage4
mov ah,9
int 21h
mov cx, 100
mov dx, offset buffer
mov cx, 100
call readstring
call crlf


;open the file
mov bx, 1
call openfile
;Time to write to the file
mov ah, 40h
mov bx, filehandler
mov cx, type snumber2
mov dx, offset snumber2
int 21h
;Close it...
mov ah, 3Eh
mov bx, filehandler
int 21h
;open the file again
mov bx, 0
call openfile
;Read from it.
xor ax,ax
mov ah,3Fh
mov bx, filehandler
mov cx, type snumber3
mov dx, offset snumber3
int 21h
;Close it... Again.
mov ah, 3Eh
mov bx, filehandler
int 21h
;Print the stuff out.
mov dx, offset readmsg
mov ah,9
int 21h
mov ebx, offset snumber3
mov eax,snumber3.num1
call writeint
call crlf
mov eax,snumber3.num2
call writeint




exit
_main ENDP

openfile proc

;Time to open the file
mov dx, 10h + 01h
mov ax, 716Ch
mov cx, 0
mov si, offset buffer
int 21h
jc erroropen
mov filehandler, ax
jmp endofproc

erroropen:
mov dx, offset erroropening
mov ah,9
int 21h


endofproc:
ret
openfile endp

end _main

Nimue

Never fails. After asking the question I figured it out.

The jumps went to labels that shared variable names.

UtillMasm


hutch--

Nimue,

One warning, dumping your homework in here and asking people to fix it is a NO NO. Read our rules and start doing your own work and we will allow you to post in here but keep dumping your homework in here and we will remove you instead.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Nimue

Fine, fine, fine. I only posted in here as a last resort. And, like, I got it working both times without the help of members.

Not using it as an excuse, just... Saying I guess. I deeply apologize and it won't happen again.

jj2007

Quote from: Nimue on December 07, 2009, 07:38:48 AM
Fine, fine, fine. I only posted in here as a last resort. And, like, I got it working both times without the help of members.

Welcome to the Forum, Nimue :thumbu

@Hutch: Normally I fully agree, but he seems to be working hard and seriously. If only he could be convinced to drop the 16-bits stuff... :bg