Question

I am new to assembly and creating a program that takes a value in the AX register, say F43A, and converts it to its ascii string in decimal.

For instance, AX = 8EFFh would print out -28929. (Convert 2s complement to ascii)

I am having trouble with comprehending the registers. Do I have to convert the AX register to decimal first, or is that implied that if AX = 000Ah in hex that AX is also equal to 10 in decimal.

So does

mov AX,000Ah
cmp AX,10

work?

Any help would be appreciated. We will be using the reduction of powers algorithm, which will be based off the decimal value of AX. Though the input value of AX will be in Hex.

If that doesn't work, how would I get the decimal value out of AX?

No correct solution

OTHER TIPS

CPUs fundamentally know only binary. The assembler, compiler or disassembler only provide convenience utilities to assist inputting or outputting the data in higher levels of abstraction (such as grouping to hex-digits or decimals, signed or unsigned, floating points and instructions such as cmp ax, 10).

Both cmp ax, 10 and some variety of cmp ax, 0x0a or cmp ax, $a or cmp ax, 000ah all encode to the same instruction: xx 0a.

Your task indeed is using instructions knowing only "numbers" split a 16-bit number (e.g. 8EFF) to it's components (array of length 1..5) and output it using ASCII conversion.

When implementing the reduction of powers algorithm, notice that the 8086 DIV instructions use the register pair DX:AX as the input.

You can get the digits in reverse order by dividing by 10, then the remainder is the last digit, then divide by 10 again, the remainder is the next to last digit, ...

or you can divide by 10,000 and the quotient is the first digit unless it's zero. Then divide the remainder by 1000, and the quotient is the next digit, ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top