From ca6447cd145acddb09b8674cb13bf0423c4b42b8 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 28 Jan 2022 00:15:21 +0500 Subject: [PATCH] Move func "print_number" to common module --- src/x86/common.S | 35 +++++++++++++++++++++++++++++++++++ src/x86/stage1.S | 37 ------------------------------------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/x86/common.S b/src/x86/common.S index f30d0c8..17962e3 100644 --- a/src/x86/common.S +++ b/src/x86/common.S @@ -6,6 +6,7 @@ .global hang .global print_char .global print_str +.global print_number .section .text hang: @@ -30,3 +31,37 @@ print_str: jz do_ret call print_char jmp print_str + +// AX - number +print_number: + test %ax, %ax + jnz print_number_notnull + mov $0x0e, %ah + mov $'0', %al + int $0x10 + ret + +// AX - number +print_number_notnull: + test %ax, %ax + jz do_ret + + // DX - dividend high (always zero) + // AX - dividend low + xor %dx, %dx + // BX - divisor (always 10) + mov $10, %bx + // AX - quotient + // DX - remainder + div %bx + + push %dx + call print_number_notnull + pop %dx + + mov $0x0e, %ah + mov %dl, %al + add $'0', %al + int $0x10 + + ret diff --git a/src/x86/stage1.S b/src/x86/stage1.S index d2ff1a9..d01d1c8 100644 --- a/src/x86/stage1.S +++ b/src/x86/stage1.S @@ -108,43 +108,6 @@ finish: ljmp $0, $STAGE2_BASE ljmp $0, $hang -do_ret: - ret - -// AX - number -print_number: - test %ax, %ax - jnz print_number_notnull - mov $0x0e, %ah - mov $'0', %al - int $0x10 - ret - -// AX - number -print_number_notnull: - test %ax, %ax - jz do_ret - - // DX - dividend high (always zero) - // AX - dividend low - xor %dx, %dx - // BX - divisor (always 10) - mov $10, %bx - // AX - quotient - // DX - remainder - div %bx - - push %dx - call print_number_notnull - pop %dx - - mov $0x0e, %ah - mov %dl, %al - add $'0', %al - int $0x10 - - ret - // AX - size print_stage2_size: push %ax