1 Replies - 850 Views - Last Post: 02 July 2011 - 10:37 AM Rate Topic: -----

#1 kenareb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-March 09

Numeric input not correct Assembly

Posted 02 July 2011 - 10:00 AM

When I run my code and I am asked to input an integer, what seems to be happening when I input an integer, no matter which key I hit it is giving me a sequential number from 0 to 9. I am not real sure as to what is going on. It worked fine the other day and now its doing its own thing. I would appreciate it if you could look at the code for me.
TITLE MASM Template						(main.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc

.data
myTitle	BYTE		"Least Common Multiple", 0dh, 0ah, 0
myMsgOne	BYTE		"Enter first integer: ", 0dh, 0ah, 0
myMsgTwo	BYTE		"Enter second integer: ", 0dh, 0ah, 0
myMsgThree BYTE	"LCM is: ", 0
myMsgFour	Byte		"This is not a prime number ", 0dh,0ah, 0

x		DWORD	?
y		DWORD	?
;t		DWORD	?
lcm		DWORD	?
gcd		DWORD	?
quotient  BYTE	?
remainder	BYTE	?


.code
main PROC
	call Clrscr
	
	mov	edx,OFFSET	myTitle			;title of exercise		
	call WriteString
	
	call crlf
	
	mov	edx,OFFSET	myMsgOne			;prompt for first int
	call WriteString
	
	call crlf
	
	call ReadInt						;read first int
	mov	x, eax
			
	mov edx,OFFSET		myMsgTwo			;prompt for 2nd int
	call WriteString
	
	call crlf
	
	call ReadInt
	mov y, eax
	
	push esi							;Move x and y inputs to temp ebx and esi
	mov esi, x
	mov ebx, y
	
	
LeastCommonDenominator:					;least common denominator
	cmp  ebx,0
	je   LeastCommonMultiple
	mov  ecx,ebx
	mov  eax,esi
	xor  edx,edx
	div  ebx
	mov  ebx,edx
	mov  eax, ecx
	mov  esi, eax
	jmp  LeastCommonDenominator

LeastCommonMultiple:					; least common multiple
	pop esi
	mov gcd, eax
	mov eax,x
	mul y
	div gcd
	mov lcm,eax

	mov edx, OFFSET myMsgThree			;display least common multiple
	call WriteString
	mov  lcm, eax
	call WriteDec
	call crlf

;	mov eax,x							;not a prime number
;	aad
;	mov bl,2
;	div bl
;	mov quotient, al
;	mov remainder, ah
;	.IF remainder == 0
;	
;	
;	mov edx, OFFSET myMsgFour
;	call WriteString
;	call crlf
;	.ENDIF


	call	waitMsg
	
	
	exit
main ENDP

END main


Is This A Good Question/Topic? 0
  • +

Replies To: Numeric input not correct Assembly

#2 kenareb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-March 09

Re: Numeric input not correct Assembly

Posted 02 July 2011 - 10:37 AM

View Postkenareb, on 02 July 2011 - 11:00 AM, said:

When I run my code and I am asked to input an integer, what seems to be happening when I input an integer, no matter which key I hit it is giving me a sequential number from 0 to 9. I am not real sure as to what is going on. It worked fine the other day and now its doing its own thing. I would appreciate it if you could look at the code for me.
TITLE MASM Template						(main.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc

.data
myTitle	BYTE		"Least Common Multiple", 0dh, 0ah, 0
myMsgOne	BYTE		"Enter first integer: ", 0dh, 0ah, 0
myMsgTwo	BYTE		"Enter second integer: ", 0dh, 0ah, 0
myMsgThree BYTE	"LCM is: ", 0
myMsgFour	Byte		"This is not a prime number ", 0dh,0ah, 0

x		DWORD	?
y		DWORD	?
;t		DWORD	?
lcm		DWORD	?
gcd		DWORD	?
quotient  BYTE	?
remainder	BYTE	?


.code
main PROC
	call Clrscr
	
	mov	edx,OFFSET	myTitle			;title of exercise		
	call WriteString
	
	call crlf
	
	mov	edx,OFFSET	myMsgOne			;prompt for first int
	call WriteString
	
	call crlf
	
	call ReadInt						;read first int
	mov	x, eax
			
	mov edx,OFFSET		myMsgTwo			;prompt for 2nd int
	call WriteString
	
	call crlf
	
	call ReadInt
	mov y, eax
	
	push esi							;Move x and y inputs to temp ebx and esi
	mov esi, x
	mov ebx, y
	
	
LeastCommonDenominator:					;least common denominator
	cmp  ebx,0
	je   LeastCommonMultiple
	mov  ecx,ebx
	mov  eax,esi
	xor  edx,edx
	div  ebx
	mov  ebx,edx
	mov  eax, ecx
	mov  esi, eax
	jmp  LeastCommonDenominator

LeastCommonMultiple:					; least common multiple
	pop esi
	mov gcd, eax
	mov eax,x
	mul y
	div gcd
	mov lcm,eax

	mov edx, OFFSET myMsgThree			;display least common multiple
	call WriteString
	mov  lcm, eax
	call WriteDec
	call crlf

;	mov eax,x							;not a prime number
;	aad
;	mov bl,2
;	div bl
;	mov quotient, al
;	mov remainder, ah
;	.IF remainder == 0
;	
;	
;	mov edx, OFFSET myMsgFour
;	call WriteString
;	call crlf
;	.ENDIF


	call	waitMsg
	
	
	exit
main ENDP

END main

This works with virtual keyboard, but not with actual keyboard. Do you have any clue as to why this is happening?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1