Hi guys, this is my first post here. I've been programming in assembly for about six months now as a hobby and enjoying it.
I've got a problem: I have made a routine called ConvertByte2Decimal that converts a byte in memory to an ASCII decimal string at a specified address. It works fine until it reaches the number 160 and above. It seems to go back to 001. I think if someone with fresh eyes may spot the problem.
Here's the code:
This has caused me many sleepless nights. :sad: Any help will be geatly appreciated.
NOTE: It's coded in 16 BIT NASM assembly.
I've got a problem: I have made a routine called ConvertByte2Decimal that converts a byte in memory to an ASCII decimal string at a specified address. It works fine until it reaches the number 160 and above. It seems to go back to 001. I think if someone with fresh eyes may spot the problem.
Here's the code:
Start:
MOV AL,
MOV SI, string
CALL ConvertByte2Decimal
MOV DX, string
MOV CX, length
CALL Write
JMP Exit
;DX: String Address
;CX: Length
Write:
MOV BX, 1
MOV AH, 40H
INT 21H
RET
;----------------------------------------------------------------------------
; Routine Name : ConvertByte2Decimal
; Version : 1.0
; Created : 24/10/2008
; Last Update : 2/11/2008
; Author : Grich
; Description : Converts a byte in memory to a decimal string
; Prerequisites : AL: Byte to be converted
; DS: Segment of destination string
; SI: Offset of destination string
;---------------------------------------------------------------------------
ConvertByte2Decimal:
MOV BL, 0AH
MOV AH, 0H ;Clears out Higher Bytes in AX for the Divide
DIV BL ;Divide AX by 0AH (10D)
CMP AL, 0AH ;COMPARE AL to 0AH (10D)
JNAE smallNumber ;IF AL !>= 0AH GOTO smallNumber
MOV DX, AX ;Saves the answer to DX
AND AX, 0FH ;Mask out Higher level Byte in AX
DIV BL ;Divide AX by 0AH (10D)
ADD AL, 30H ;Convert AL to ASCII equivelent
ADD AH, 30H ;Convert AH to ASCII equivelent
MOV , AL ;Move Quotent to postion 0
MOV , AH ;Move Remainder to position 1
MOV AX, DX ;Move DX back to AX
JMP continueConvert ;Continue on to put character three down in the string
smallNumber:
MOV BYTE , 20H ;Move a space character to position 0
ADD AL, 30H ;Convert AL toto ASCII equivelent
MOV , AL ;Move Quotent to postion 1
continueConvert:
ADD AH, 30H ;Convert AH toto ASCII equivelent
MOV , AH ;Move Remainder to position 2
RET ;Return to Caller
Exit:
MOV AH, 4CH
MOV AL, 0
INT 21H
string DB " "
length EQU $-string
number DB 190This has caused me many sleepless nights. :sad: Any help will be geatly appreciated.
NOTE: It's coded in 16 BIT NASM assembly.