flat assembler
Message board for the users of flat assembler.

Index > DOS > convert decimal into hexa

Author
Thread Post new topic Reply to topic
biran



Joined: 13 Oct 2008
Posts: 1
biran
hi all,
i am beginner with assembly language.
please help me out with small source code.
i want to convert decimal number into hexa.
i did like this:

.MODEL SMALL
.DATA
TEN DB 10
VAR1 DB 0
INDEC DB 0,1
M1 DB 'Enter Decimal : ','$'
M2 DB 13,10,'Hex Value: ','$'
.STACK
.CODE
.STARTUP
LEA DX,M1
MOV AH,9
INT 21H

MOV AH,1
INT 21H

SUB AL,0
MOV INDEC+1,AL
ADD AL,VAR1
MOV VAR1,AL

LEA DX,M2
MOV AH,9
INT 21H

MOV AL,INDEC
ADD AL,0
MOV DL,AL
MOV AH,2
INT 21H

MOV AL,INDEC+1
ADD AL,0
MOV DL,AL
MOV AH,2
INT 21H

mov ah, 2
mov dl, 'h'
int 21h

END

but this is not good idia

_________________
blim
Post 13 Oct 2008, 18:24
View user's profile Send private message Yahoo Messenger Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
It's not working because it's not fasm code (tasm?).

remove .MODEL SMALL, .DATA, .STACK, .CODE, .STARTUP, END
move all your data to the end
use brackets for memory locations (e.g. 'mov [var1],al' instead of 'mov var1,al')
don't forget the 'org 100h'
add some exit code at the end
and why not use 'mov' instead of 'lea'?

N.B. This code converts only one digit.
Post 14 Oct 2008, 07:21
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
ManOfSteel wrote:

not working because
remove .MODEL SMALL
move all your data to the end
use brackets for memory
don't forget the 'org 100h'
some exit code at the end
why not use 'mov' instead of 'lea'?
code converts only one digit.


All right Smile

Exit code:

Code:
  ret ; COM only
    


Code:
  mov ax,$4C00
  int  $21  ; COM , RM EXE , DPMI EXE
    


Not required but nice to have at beginning:

Code:
; Compile with FASM

format binary as "COM"
    


About converting dec to hex, you need 2 things:

- Parse DEC input
- Output as HEX

Check some of my examples Idea

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 15 Oct 2008, 23:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.