Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

get the percentage of 2 digit numbers by a user

assembly

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 hockie

hockie

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 24 March 2015 - 12:06 PM

I need help dealing with divide overflow output.

i know its the "div" but im not too familiar with assembly, and im just starting to use it.

I already searched some forums but can't find the exact solution. 

Can you please guide me how to fix my code?

JMP START

 DIVIDEND DB ?
 DIVISOR DB '4'


 QUOTIENT DB 4 DUP(0), '$'

 MSG1 DB 'NUMBER OF SCORE: $'
 MSG2 DB 'NUMBER OF ITEMS: $'
 LINE DB 0AH, 0DH, '$'


START:
 MOV CX, 4
 SUB AX, AX
 AND DIVISOR, 0FH

 MOV SI, OFFSET DIVIDEND
 MOV DI, OFFSET QUOTIENT

ASCII_DIVIDE:
LODSB
AND AX, 0FH
AAD
DIV DIVISOR
STOSB
LOOP ASCII_DIVIDE

MOV BX, OFFSET QUOTIENT
MOV CX, 4

 MOV DX, OFFSET MSG1
 MOV AH, 9
 INT 21H

 MOV DX, OFFSET DIVISOR
 MOV AH, 0AH
 INT 21H

	MOV DX, OFFSET LINE
	MOV AH, 9
	INT 21H

 MOV DX, OFFSET MSG2
 MOV AH, 9
 INT 21H

 MOV DX, OFFSET DIVIDEND
 MOV AH, 0AH
 INT 21H

	MOV DX, OFFSET LINE
	MOV AH, 9
	INT 21H

 MOV SI, OFFSET DIVIDEND
 MOV AX, [SI]
 AND AX, 0FH
 MOV DI, OFFSET DIVISOR
 MOV BX, [DI]
 AND BX, 0FH
    MOV AX, 0
    MOV BX, 0
MOV CX, 2
    MOV DX, OFFSET LINE
    MOV AH, 0AH
    INT 21H
DIVIDE:
 DIV BL
 PUSH AX
 OR AL, 30H
 MOV DL, AL
 MOV AH, 2
 INT 21H
 POP AX
 MOV BL, AH

CONVERT:

 MOV AX, 10
 MUL BL
 MOV BL, 4
 DIV BL
 OR AL, 30H
 MOV DL, AL
 PUSH AX
 MOV AH, 2
 INT 21H
 POP AX
 MOV AL, 0
 MOV BL, AH
 LOOP CONVERT

MOV DL, '%'
MOV AH, 2
INT 21H

CONVERT_AND_DISPLAY:
OR BYTE PTR[BX], 30H
INC BX
LOOP CONVERT_AND_DISPLAY

RET 


#2 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 24 March 2015 - 12:43 PM

What exactly is your problem, and where do you think it is? Explaining it to me should help you a bit.


sudo rm -rf / && echo $'Sanitize your inputs!'


#3 hockie

hockie

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 24 March 2015 - 07:30 PM

hi,

 

the problem is it suppose to compute (number1/number2)*100,

after the number2 input it returns "divide overflow".

i think its in line 84

 

any thought?

 

thanks



#4 hockie

hockie

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 25 March 2015 - 12:11 AM

can you please help me dargueta?

#5 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 29 March 2015 - 10:50 AM

Yeah, sorry, I was busy. I'm looking at this right now.

 

Edit: Your problem is on line 64. You set BX = 0 then on line 70 you divide AL by it.


Edited by dargueta, 29 March 2015 - 10:52 AM.

sudo rm -rf / && echo $'Sanitize your inputs!'