I was wondering if it is possible to subtract 30 from 4ah? i thought so i can convert the ascii character 'C' to hexadecimal '43', i will just subtract 30h from 43h, then add 30 so it will become 43 again and i will be able to perfrom arithmetic on it, but then i realized, what about when the hexadecimal has letters on it? hmm. help please!

I was wondering if it is possible to subtract 30 from 4ah? i thought so i can convert the ascii character 'C' to hexadecimal '43', i will just subtract 30h from 43h, then add 30 so it will become 43 again and i will be able to perfrom arithmetic on it, but then i realized, what about when the hexadecimal has letters on it? hmm. help please!

Hi cmsc,

I am glad that we have solved your other task. Fortunately, your new homework is much more easier than the one which required int inputs, just about a full dozen of instructions, all dealing with 8 bit registers, currently no MULs :cool:

-- tesu

what's MULs? i really don't know. happy to see your reply :D i really don't know what to do with this. this is the number two in my homework :)

is my approach correct? I'm having doubts with the 4ah - 30h thing.

Sorry, drop the s, so MUL stands for the unsigend multiply instruction.

Number-two homework? But this one is easy by contrast with your first one.

True, there are reasonable doubts in going that way, Jay-Z usually says. Its really easier because of one hexadecimal digit stands for four binary digits. So start by splitting 8 bits into two nibbles (4bits long, do not mistaken that american word :ooh:)

-- tesu

so the 4ah will become 4 and a? but both will be stored in al, so how will i be able to separate that?

so the 4ah will become 4 and a? but both will be stored in al, so how will i be able to separate that?

Hi

Here is some code for processing the lower nibble (e.g. hex digit A of 4AH)

;....
	mov	dl, [bx]		; 2. processing bits 3 .. 0
	and	dl, 0fh			; clear bits 7 .. 4
	add	dl, 30h			; add '0' to make an ascii for output (!)
	cmp	dl, 3ah			; compare it with  3ah
	jb	lo			; hex digit   '0' .. '9'
	add	dl, 7h			; hex digit 'A' .. 'F' 
lo:     int     21h		        ; doscall, output <cl> on screen
;...

[bx] points to a char array in data segement, for example

chars	db 'abcdefghijklmnopqrstuvwxyz'	; to be output by hex$out
cends	db ?		; create a symbol to calculate number of chars

; then in code segment load byte ptr to chars array:
mov	bx, byte ptr chars	; start offset

Now you should reason how to process higher nibble (e.g. hex digit 4 of 4AH), for that you need a shr instruction (don't use cl reg)

-- tesu

got it! thank you very much :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.