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.
;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
Now I *think* I'm getting a similar problem further down with my code.
OK here's the debugging info:
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
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.
|04-19-2005, 10:09 AM||
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.
sub al, 30
(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:
who needs General [H]ospital when you got General [M]ayhem?
Last edited by plot; 04-19-2005 at 02:10 PM..
|04-19-2005, 02:07 PM||
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.
|12-27-2011, 08:46 AM||
Go pop a stack of 8086 cocks
|12-27-2011, 09:13 AM||
how can I do that ..?
this is my code if you can show me where is the problem :
TITLE "SLEEP Time Program Implementation"
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,"$"
START: MOV CL,4
Q: MOV AH,01H
CLOCK: LEA SI,TIME1
EXIT: CALL CLEARSCREEN
DELAY: MOV AH,02CH
LL: INT 21H
|12-27-2011, 09:17 AM||
Write the program in C, then:
$ gcc -Wall -ansi -S your_program.c
"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."
|12-27-2011, 01:37 PM||