General [M]ayhem

Go Back   General [M]ayhem > Real Time Sub-Forums > CompuGlobalHyperMegaNet
Register Members List Mark Forums Read [M]erchandise Calendar

Reply
 
Thread Tools
Mertous
 
God I hate assembly language

Right what it's MEANT to do is generate a random number (1-5), then get an integer from the user, then compare the two numbers and see if they match. Basically it's a really fun guessing game between you and the computer!!!!!!......

All works fine - it all compiles BUT whatever integer I input (1,2,3,4 or 5) it still tells me that it's not the same as the random number generated.

OK code:

Code:
;generate a random integer
	MOV AH,2Ch		;DOS call to get system clock
	INT 21h			;Execute interrupt 21H
	MOV AL,DL		;Result returned in DL
	MOV AH,0		;Clear the High byte
	MOV CL,20h		;Get divisor
	DIV CL			;Divide value in AX by value in CL
	MOV BL,AL		;Move result of division into BL
	INC BL			;Increment BL to get number between 1-5

;define a few useful constants
	CR equ 13 		;RETURN is 13D ASCII
	LF equ 10		;LINE FEED is 10D ASCII

	JMP START		;Skip over messages - jump to START
	
;define the prompt message
MESSAGEPROMPT:
	DB "Please enter an integer (1-5)",CR,LF,"$"
	
;define the correct message
MESSAGECORRECT:
	DB " Well done, that was the correct number",CR,LF,"$"

;define the incorrect message
MESSAGEINCORRECT:
	DB " Sorry, that was not the correct number. Try again",CR,LF,"$"


START:	

;output prompt message
	MOV DX,MESSAGEPROMPT	;put address of the message in DX
	MOV AH,9		;MS-DOS Print string function
	INT 21h			;call DOS

;read input
	MOV AL,0		;clear the low byte
	MOV AH,1 		;wait for input and put it in AL
	INT 21h			;call DOS

;compare the two integers
	CMP BL,AL		;compare integers in BL and AL
	JE  CORRECT		;if equal, jump to CORRECT
	
;output incorrect message
	MOV DX,MESSAGEINCORRECT	;put address of the message in DX
	MOV AH,9		;MS-DOS Print string function
	INT 21h			;call DOS

;start again
	JMP START

CORRECT:
	MOV DX,MESSAGECORRECT	;put address of the message in DX
	MOV AH,9		;MS-DOS Print string function
	INT 21h			;call DOS
	MOV AH,4ch		;MS-DOS Exit to DOS function
	INT 21h			;call DOS
Right now I've been debugging this MOFO all day, and have actually got some info. To start with the divisor was being put into the register (CL) as 14, rather than 20. Now it's going in as 20 as I shoved an h on the end of the 20 which I think tells the computer that it's in hex or something like that. Hell I don't care, it fixed that problem anyway.

Now I *think* I'm getting a similar problem further down with my code.

OK here's the debugging info:
Code:
AX=0902  BX=0003  CX=1220  DX=0113  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=1538  ES=1538  SS=1538  CS=1538  IP=0197   NV UP EI PL NZ NA PE NC
1538:0197 CD21          INT     21
-p
Please enter an integer (1-5)

AX=0924  BX=0003  CX=1220  DX=0113  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=1538  ES=1538  SS=1538  CS=1538  IP=0199   NV UP EI PL NZ NA PE NC
1538:0199 B000          MOV     AL,00
-t

AX=0900  BX=0003  CX=1220  DX=0113  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=1538  ES=1538  SS=1538  CS=1538  IP=019B   NV UP EI PL NZ NA PE NC
1538:019B B401          MOV     AH,01
-t

AX=0100  BX=0003  CX=1220  DX=0113  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=1538  ES=1538  SS=1538  CS=1538  IP=019D   NV UP EI PL NZ NA PE NC
1538:019D CD21          INT     21
-p
3
AX=0133  BX=0003  CX=1220  DX=0113  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=1538  ES=1538  SS=1538  CS=1538  IP=019F   NV UP EI PL NZ NA PE NC
1538:019F 38C3          CMP     BL,AL
-t

AX=0133  BX=0003  CX=1220  DX=0113  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=1538  ES=1538  SS=1538  CS=1538  IP=01A1   NV UP EI NG NZ NA PO CY
1538:01A1 7409          JZ      01AC
that debugging info is running from ";output prompt message" where it says 'INT21h'.

Now as you can see, in BL is the randomly generated number (03). So, when it asks for an input, I input 3 (the correct number) but rather than AL taking the value of 03, it takes the value of 33. me=

If I input 2, it takes the value of 32.

Why this is I have no idea, but I suspect it's something to do with converting between octal and hex perhaps. Anyway sure enough when it then compares AL to BL it complains and says they're not similar, which obviously they're not.
So, how do I fix?

Thanks for any help. And if you even read all that you deserve a medal.
Old 04-19-2005, 10:09 AM Mertous is offline  
Reply With Quote
#1  

Advertisement [Remove Advertisement]

plot
this is plot from http://plot.brainwashed.us
 
easy, it's throwing the ascii values into the register, not "2"...

the best way to do this is to subtract 30 from the the register before comparing, as all numbers inputted from the keyboard will always have that extra 30 on there.

something like:
sub al, 30
CMP BL,AL
JZ 01AC

(i don't use x86 assmebly often, so it might not be sub and i'm to lazy to look it up )

edit: check out the ascii chart, you'll see why there's an extra 30 for numbers, the first 29 values are for control keys and whatever else http://www.jimprice.com/jim-asc.htm
__________________
everything you need to know for genmay is right here:
http://www.brainwashed.us/plot/index.html

drama......
who needs General [H]ospital when you got General [M]ayhem?

Last edited by plot; 04-19-2005 at 02:10 PM..
Old 04-19-2005, 02:07 PM plot is offline  
Reply With Quote
#2  

barking frog
 
www.asciitable.com

learn it, use it, love it
Old 04-19-2005, 02:11 PM barking frog is offline  
Reply With Quote
#3  

samual11
 
Hello,

I have a problem and I couldn't solve it
I really hate Assemble Language

The problem says:

You should ask me to enter the SLEEP time.

Then you program will compare the Clock time of PC with
my entered SLEEP time.

When both time are equal, your program will
display SLEEP ==> this display will be terminated
with a key press (instead for few second).
This way the speed difference of the PC's (your labtop and my office PC)
will not matter.
Old 12-27-2011, 08:46 AM samual11 is offline  
Reply With Quote
#4  

-=Antimatter=-
 
-=Antimatter=-'s Avatar
 
Quote:
Originally Posted by samual11 View Post
Hello,

I have a problem and I couldn't solve it
I really hate Assemble Language

The problem says:

You should ask me to enter the SLEEP time.

Then you program will compare the Clock time of PC with
my entered SLEEP time.

When both time are equal, your program will
display SLEEP ==> this display will be terminated
with a key press (instead for few second).
This way the speed difference of the PC's (your labtop and my office PC)
will not matter.

Go pop a stack of 8086 cocks
__________________
wat
Old 12-27-2011, 09:13 AM -=Antimatter=- is offline  
Reply With Quote
#5  

samual11
 
how can I do that ..?

this is my code if you can show me where is the problem :



TITLE "SLEEP Time Program Implementation"
.MODEL SMALL
.STACK 100
.DATA

LF EQU 10
CR EQU 13

MSG1 DB 'PLEASE ENTER SLEEP TIME:$'
ASAR DB 4 DUP(?)
TIME1 DB 4 DUP(?)
MSG2 DB "SLEEP TIME",LF,CR,"$"

.CODE

ORG 100H

MAIN PROC

MOV AX,@DATA
MOV DS,AX


START: MOV CL,4
MOV AH,9
LEA DI,MSG1
MOV DX,DI
INT 21H

LEA SI,TIME1

Q: MOV AH,01H
INT 21H
SUB AL,30H
MOV [SI],AL
DEC CL
CMP CL,0
JE CLOCK
INC SI
JMP Q




CLOCK: LEA SI,TIME1
MOV AH,2CH
INT 21H
MOV AL,CH
SUB AL,30H
MOV [SI],AX
MOV AL,CL
SUB AL,30H
MOV [SI+2],AX
CMP SI,AX
JNE START





EXIT: CALL CLEARSCREEN
MOV DH,10
MOV DL,13
CALL SETCURSOR

MOV AH,9
LEA DI,MSG2
MOV DX,DI
INT 21H


DELAY: MOV AH,02CH
LL: INT 21H
CMP DH,1
JNE LL


MOV AX,4C00H
INT 21H



MAIN ENDP

CLEARSCREEN PROC

MOV AH,00
MOV AL,03
INT 10H
RET

CLEARSCREEN ENDP

SETCURSOR PROC

MOV AH,2
MOV BH,0
INT 10H
RET

SETCURSOR ENDP



END MAIN
Old 12-27-2011, 09:17 AM samual11 is offline  
Reply With Quote
#6  

Scatman
 
Scatman's Avatar
 
Write the program in C, then:
Code:
$ gcc -Wall -ansi -S your_program.c
__________________
Code:[M]ayhem: Owned.
http://www.genmay.com/showthread.php?t=804869

"I'm gonna be rich and famous one day when I invent
a device that can be used to stab someone in the
face over the Internet."
Old 12-27-2011, 01:37 PM Scatman is offline  
Reply With Quote
#7  

-=Antimatter=-
 
-=Antimatter=-'s Avatar
 
Wow, srsly thought he was a bot
__________________
wat
Old 12-27-2011, 06:25 PM -=Antimatter=- is offline  
Reply With Quote
#8  

Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -7. The time now is 10:04 PM.



Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.