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 $@ $<
|
$(AS) $(ASFLAGS) -o $@ $<
|
||||||
$(OBJCOPY) --remove-section .note.gnu.property $@
|
$(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)
|
mbr_test: $(MBR_TEST_OBJ) $(DISK)
|
||||||
$(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ)
|
$(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
# eax - number
|
# eax - number
|
||||||
# ecx - base
|
# ecx - base
|
||||||
|
# return - ds:si pointing to string number
|
||||||
itoa:
|
itoa:
|
||||||
push %bx
|
push %bx
|
||||||
xor %edx, %edx
|
xor %edx, %edx
|
||||||
|
|
@ -36,7 +37,7 @@ itoa:
|
||||||
# we return ptr to string, since we're pushing chars in reverse, therefore
|
# we return ptr to string, since we're pushing chars in reverse, therefore
|
||||||
# beginning of string will change
|
# beginning of string will change
|
||||||
inc %di
|
inc %di
|
||||||
mov %di, %ax
|
mov %di, %si
|
||||||
|
|
||||||
pop %bx
|
pop %bx
|
||||||
ret
|
ret
|
||||||
|
|
@ -45,4 +46,4 @@ itoa:
|
||||||
.comm itoa_result, ITOA_BUFFER_SIZE
|
.comm itoa_result, ITOA_BUFFER_SIZE
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
numbers: .ascii "0123456789ABCDEF"
|
numbers: .ascii "0123456789ABCDEF"
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,8 @@ entry:
|
||||||
|
|
||||||
# it's working fixed disk, lets print its number
|
# it's working fixed disk, lets print its number
|
||||||
movw disk_id, %ax
|
movw disk_id, %ax
|
||||||
mov $10, %cx
|
mov $disk_enum_msg, %si
|
||||||
call itoa
|
call prints_number
|
||||||
|
|
||||||
mov %ax, %si
|
|
||||||
call prints
|
|
||||||
|
|
||||||
mov $'\n', %al
|
|
||||||
call serial_putc
|
|
||||||
.disk_skip:
|
.disk_skip:
|
||||||
decw disk_id
|
decw disk_id
|
||||||
jns .disk_enum
|
jns .disk_enum
|
||||||
|
|
@ -68,5 +62,8 @@ entry:
|
||||||
.halt:
|
.halt:
|
||||||
jmp .halt
|
jmp .halt
|
||||||
|
|
||||||
|
.section .rodata
|
||||||
|
disk_enum_msg: .asciz "Disk "
|
||||||
|
|
||||||
.section .bss
|
.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