From 1a052f3a6cf64350f2c1ff407f032e9729172a34 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Sun, 4 Aug 2024 19:50:13 +0300 Subject: [PATCH] done with itoa function --- src/itoa.s | 13 +++++++++---- src/mbr_test.s | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/itoa.s b/src/itoa.s index 117bfbc..9d0d0d4 100644 --- a/src/itoa.s +++ b/src/itoa.s @@ -13,24 +13,29 @@ itoa: mov $numbers, %bx mov $(itoa_result + ITOA_BUFFER_SIZE - 1), %di + movb $0, (%di) + dec %di std .div: divl %ecx - or %eax, %eax - jz .end # we run out of numbers # yep, we're using LUT for number -> character conversion since ASCII is a fuck push %eax - add %bx, %ax + movb (%ebx,%edx,1), %al stosb pop %eax - jmp .div + xor %edx, %edx + + or %eax, %eax + jnz .div .end: + # we run out of numbers cld # we return ptr to string, since we're pushing chars in reverse, therefore # beginning of string will change + inc %di mov %di, %ax pop %bx diff --git a/src/mbr_test.s b/src/mbr_test.s index e0d99ef..3423637 100644 --- a/src/mbr_test.s +++ b/src/mbr_test.s @@ -43,6 +43,16 @@ mov %ax, %si call prints + + mov $'\n', %al + call serial_putc + + mov $691337, %eax + mov $10, %ecx + call itoa + + mov %ax, %si + call prints .halt: jmp .halt