implement util function to print numbers with header
This commit is contained in:
parent
f4c3b1b5a6
commit
a6a65f790d
4 changed files with 35 additions and 12 deletions
2
Makefile
2
Makefile
|
|
@ -97,7 +97,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s
|
|||
$(AS) $(ASFLAGS) -o $@ $<
|
||||
$(OBJCOPY) --remove-section .note.gnu.property $@
|
||||
|
||||
MBR_TEST_OBJ = obj/mbr_test.o obj/serial.o obj/itoa.o
|
||||
MBR_TEST_OBJ = obj/mbr_test.o obj/serial.o obj/itoa.o obj/util.o
|
||||
|
||||
mbr_test: $(MBR_TEST_OBJ) $(DISK)
|
||||
$(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
# eax - number
|
||||
# ecx - base
|
||||
# return - ds:si pointing to string number
|
||||
itoa:
|
||||
push %bx
|
||||
xor %edx, %edx
|
||||
|
|
@ -36,7 +37,7 @@ itoa:
|
|||
# we return ptr to string, since we're pushing chars in reverse, therefore
|
||||
# beginning of string will change
|
||||
inc %di
|
||||
mov %di, %ax
|
||||
mov %di, %si
|
||||
|
||||
pop %bx
|
||||
ret
|
||||
|
|
@ -45,4 +46,4 @@ itoa:
|
|||
.comm itoa_result, ITOA_BUFFER_SIZE
|
||||
|
||||
.section .rodata
|
||||
numbers: .ascii "0123456789ABCDEF"
|
||||
numbers: .ascii "0123456789ABCDEF"
|
||||
|
|
|
|||
|
|
@ -52,14 +52,8 @@ entry:
|
|||
|
||||
# it's working fixed disk, lets print its number
|
||||
movw disk_id, %ax
|
||||
mov $10, %cx
|
||||
call itoa
|
||||
|
||||
mov %ax, %si
|
||||
call prints
|
||||
|
||||
mov $'\n', %al
|
||||
call serial_putc
|
||||
mov $disk_enum_msg, %si
|
||||
call prints_number
|
||||
.disk_skip:
|
||||
decw disk_id
|
||||
jns .disk_enum
|
||||
|
|
@ -68,5 +62,8 @@ entry:
|
|||
.halt:
|
||||
jmp .halt
|
||||
|
||||
.section .rodata
|
||||
disk_enum_msg: .asciz "Disk "
|
||||
|
||||
.section .bss
|
||||
disk_id: .word
|
||||
disk_id: .word
|
||||
|
|
|
|||
25
src/util.s
Normal file
25
src/util.s
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
.section .text
|
||||
.code16
|
||||
|
||||
.globl prints_number
|
||||
.globl empty_string
|
||||
|
||||
# eax - number, ds:si - header string
|
||||
prints_number:
|
||||
# header
|
||||
push %eax
|
||||
call prints
|
||||
pop %eax
|
||||
|
||||
mov $10, %cx
|
||||
call itoa
|
||||
call prints
|
||||
|
||||
# newline
|
||||
mov $'\n', %al
|
||||
call serial_putc
|
||||
|
||||
ret
|
||||
|
||||
.section .rodata
|
||||
empty_string: .byte 0
|
||||
Loading…
Add table
Reference in a new issue