ok, so here's my problem:
main:
mov eax, prompt0 ; print out prompt
call print_string
call read_char
cmp eax, 'a'
je near addition
cmp eax, 's'
je near subtraction
cmp eax, 'm'
je near multiplication
cmp eax, 'd'
je near division
cmp eax, 'o'
je near modulo
cmp eax, 'x'
je exit
jmp main
/code
for some reason when I run my program, it prints that output msg twice. this is the only part of my program that has:
mov eax, prompt0 ; print out prompt
call print_string
So I'm at a loss as to why the hell it would double up on prompt0 the second time through. anyone have any thoughts on this?
sorry, first time posting here
<code>
main:
mov eax, prompt0 ; print out prompt
call print_string
call read_char
cmp eax, 'a'
je near addition
cmp eax, 's'
je near subtraction
cmp eax, 'm'
je near multiplication
cmp eax, 'd'
je near division
cmp eax, 'o'
je near modulo
cmp eax, 'x'
je exit
jmp main
</code>
does read_char require input from the keyboard before it does that? and why doesn't it keep going and go into a loop if that's the problem? it's weird.
main:
mov eax, prompt0 ; print out prompt
call print_string
call read_char
cmp eax, 'a'
je near addition
cmp eax, 's'
je near subtraction
cmp eax, 'm'
je near multiplication
cmp eax, 'd'
je near division
cmp eax, 'o'
je near modulo
cmp eax, 'x'
je exit
jmp main
It's really not weird at all. Print out the fucking charcode and see for yourself.
Name:
Anonymous2010-11-20 18:54
read_char is a built in assembly language function that reads a single character from the keyboard and stores its ASCII code into the EAX register. the program is acting like print_string is being called twice in a row, it doesn't pause to read_char between them, instead of
Your problem is with print_string and you haven't given us any information on that at all?
Name:
op2010-11-20 19:03
sorry, print_string just prints the contents of the EAX register.
basically, i'm just moving the output string into EAX, outputting it, then it's supposed to prompt for input from the user, which it does, but after the first time through the program its like print_string gets called twice, it's weird.
>>13
Your blatant refusal to take the advice offered makes you seem more like a troll.
Name:
Anonymous2010-11-20 19:20
>>14 what advice? so far I've had people tell me to look at read_int and print_string, but they are both built into my assembler, and one just waits for user input and stores it in EAX, and the other prints out the contents of EAX.
and who trolls a programming BBS??
>>15
The advice in >>7,10 should contain the answer, if I remember the format of this troll correctly.
Name:
op2010-11-20 19:36
>>17 i think so >>18 7 doesnt tell me anything i don't already know, and 10, what's charcode?? i figured he meant the code for the function read_char, but it's built in
some of you guys are, like, too hostile. too much time on /b/ i figure. anyway figured it might have been a waste of my time to ask some strangers on the internet.
thank you to the people who tried to help, take care.
This need macroses. Just think about it
invoke print_string, prompt0
call read_char
jmpifeq eax, 'a', addition
jmpifeq eax, 's', subtraction
jmpifeq eax, 'm', multiplication
jmpifeq eax, 'd', division
jmpifeq eax, 'o', modulo
jmpifeq eax, 'x', exit
jmp main
Almost as cool as ML with its pattern matching!
No man I like my registers with a little meat on them;-), just saying that al is the perfect size for a single ASCII character so that cmp al, 'a' might be a more apt comparison.