0

I work in emulator emu8086. After I execute the mul command, I get the result in the dx:ax registers. How can I display the result?

I used an array, but I don't like this output format.

mov ax, 13
mul x2
mov cx, ax  ; 13x^2
mov ax, 26
mul x       ; 26x
sub cx, ax  ; 13x^2 - 26x
mov ax, 123 ; 123
add ax, cx  ; 13x^2 - 26x + 123
mul ax      ; (13x^2 - 26x + 123)^2
mov otvet[2], ax
mov otvet[0], dx
Mahdi
  • 9,247
  • 9
  • 53
  • 74

1 Answers1

0

16 is a power of 2, so each hex (base 16) digit only depends on 4 bits of your number, not on all higher bits. So you can print DX in hex and then separately do AX.

Save AX in memory if you need more registers. You might make a function call twice with two different inputs to store hex digits to memory. Or a loop over an arbitrary number of bytes (counting down from the highest byte, so you get the result in printing order, most-significant digit first).


There are a ton of examples of integer->hex you can google, e.g. these 8086-compatible functions.

And there's How to convert a number to hex? which explains more about the basics of why these methods work, and shows a 32-bit loop.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847