0

I tried many ways of doing this and was searching the internet for 2 hours, didn't find anything. Please help, new to assembly. I realised that I have to convert the number into a string, but I didn't succeed in doing so.

Last attempt:

pint:
    .repeat:
        mov ax, 10
        div al
        mov cl, [al]
        mov al, [ah]
        mov ah, 0Eh
        add ah, 48
        int 0x10
        sub ah, 48
        mov al, [cl]
        cmp al, 0
        je .done
        jmp .repeat
    .done:
        ret 
Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • 3
    Show your attempt. – Jester May 03 '21 at 20:07
  • Whats the langauge of assembly there alot of them NASM/MASM/FASM/SASM etc – coderx64 May 03 '21 at 20:09
  • nasm its in the tags i think – Trollge morde May 03 '21 at 20:10
  • @Jester here is my last attempt, its messy and useless i got lost in it quickly... `pint: .repeat: mov ax, 10 div al mov cl, [al] mov al, [ah] mov ah, 0Eh add ah, 40 int 0x10 sub ah, 40 mov al, [cl] cmp al, 0 je .done jmp .repeat .done: ret` – Trollge morde May 03 '21 at 20:27
  • Here perfect reference for os develop with assembly for beginner: https://github.com/cfenollosa/os-tutorial/ – coderx64 May 03 '21 at 20:33
  • 2
    Use the [edit] link to add information into your question. Also,comment your code. In particular the `add/sub` 40 are not obvious. Specify how big your number is and whether it's signed or not. – Jester May 03 '21 at 20:33
  • @Jester sorry for the mistake, the number is supposed to be 48, because 48 is zero in ascii. I'll edit it now. – Trollge morde May 03 '21 at 20:43
  • I assume the `div al` wants to divide by 10, but of course `div` uses `ax` for the dividend so that won't work. Also are you aware this method produces digits in the reverse order? – Jester May 03 '21 at 20:48
  • @Jester I wanted to specify ax before calling the function, and I know it would be in reverse. – Trollge morde May 03 '21 at 20:51
  • Also it's unclear why you `sub ah, 48` and `mov al, [cl]` is plain simply invalid. – Jester May 03 '21 at 20:52
  • @NateEldredge It kinda does, but what if there's more digits than two? – Trollge morde May 03 '21 at 20:57
  • 3
    Then see https://stackoverflow.com/questions/15621258/assembly-printing-ascii-number/15621644#15621644 or https://stackoverflow.com/questions/45904075/displaying-numbers-with-dos. These are from the [x86 tag wiki](https://stackoverflow.com/tags/x86/info) which has many other resources that you may find useful. – Nate Eldredge May 03 '21 at 20:58
  • Use any of the 1-char-at-a-time DOS print number answers, but use a BIOS call instead of a DOS call. – Peter Cordes May 04 '21 at 05:48

0 Answers0