1 Replies - 2231 Views - Last Post: 07 September 2012 - 05:09 PM

#1 btfrenchy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-September 12

reading and writing hex

Posted 07 September 2012 - 01:08 PM

hey everyone, this is my first time posting on this forum and I could really use some guidance. I'm trying to write code that asks for an input, translates that input to hex, does some kind of transformation to it, and then displays it to the user. Here is what I have so far:
 
.386
include irvine16.inc
	.data
	array byte 10 dup(?)
	ten word 10
	prompt byte "Enter something: ", 0ah, 0dh, "$"
	.code

	start Proc
	mov ax, @data
	mov ds, ax
	mov ah, 9
	mov dx, offset prompt
	int 21h ;message to the user

	;read in a number
	;work on this part
	xor bx, bx ;set bx=0
	;between here

	mov ax, bx
	xor si, si ;si=0

getnumtop:
cmp ax, 0
	je printit
	xor dx, dx ;dx =0
	div ten
	or dl, 48
	mov array[si], dl
	add si, 1 ;increment si
	jmp getnumtop

printit:
		cmp si, 0
		jL getdigit
		mov ah, 2 ;2 is dos interrupt for printing
		mov dl, array[si]
		int 21h
		dec si ;decrement si
		jmp printit
getdigit:
		sub al, 48
			cmp al, 9
			jbe gotdigit
			sub al, 7

gotdigit:
		add al, 45


	exit
	start endp
	end start



I really don't know where to go from here, I know there are probably some terrible errors, and its obviously not finished. I'd really like to understand this better and would appreciate any and all help. Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: reading and writing hex

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,303
  • Joined: 28-March 11

Re: reading and writing hex

Posted 07 September 2012 - 05:09 PM

I think you should work on this part:

Quote

;read in a number
;work on this part


You could use Int 21/AH=0Ah, Int 21/AH=07h, Int 21/AH=08h and a few others. http://www.ctyme.com/intr/int-21.htm Can I ask, WHY DOS?

Do you know how to convert a number (binary, decimal) to hexadecimal on paper?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1