diff --git a/Makefile b/Makefile index 460ee24..d0df868 100644 --- a/Makefile +++ b/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) diff --git a/src/itoa.s b/src/itoa.s index 9d0d0d4..a8878f1 100644 --- a/src/itoa.s +++ b/src/itoa.s @@ -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" \ No newline at end of file +numbers: .ascii "0123456789ABCDEF" diff --git a/src/mbr_test.s b/src/mbr_test.s index 04e4805..9c3a7d5 100644 --- a/src/mbr_test.s +++ b/src/mbr_test.s @@ -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 diff --git a/src/util.s b/src/util.s new file mode 100644 index 0000000..6a65d42 --- /dev/null +++ b/src/util.s @@ -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