begin working on itoa
This commit is contained in:
parent
8825664287
commit
f86a560f3e
3 changed files with 57 additions and 1 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
|
||||
MBR_TEST_OBJ = obj/mbr_test.o obj/serial.o obj/itoa.o
|
||||
|
||||
mbr_test: $(MBR_TEST_OBJ) $(DISK)
|
||||
$(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ)
|
||||
|
|
|
|||
45
src/itoa.s
Normal file
45
src/itoa.s
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
.section .text
|
||||
.code16
|
||||
|
||||
.globl itoa
|
||||
|
||||
.equ ITOA_BUFFER_SIZE, 12
|
||||
|
||||
# eax - number
|
||||
# ecx - base
|
||||
itoa:
|
||||
push %bx
|
||||
mov $numbers, %bx
|
||||
|
||||
.debug:
|
||||
jmp .debug
|
||||
|
||||
mov $(itoa_result + ITOA_BUFFER_SIZE - 1), %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
|
||||
stosb
|
||||
pop %eax
|
||||
|
||||
jmp .div
|
||||
.end:
|
||||
cld
|
||||
|
||||
# we return ptr to string, since we're pushing chars in reverse, therefore
|
||||
# beginning of string will change
|
||||
mov %di, %ax
|
||||
|
||||
pop %bx
|
||||
ret
|
||||
|
||||
.section .bss
|
||||
.comm itoa_result, ITOA_BUFFER_SIZE
|
||||
|
||||
.section .rodata
|
||||
numbers: .ascii "0123456789ABCDEF"
|
||||
|
|
@ -29,11 +29,22 @@
|
|||
mov %ax, %ss
|
||||
xor %sp, %sp
|
||||
|
||||
# set ES segment
|
||||
push %ds
|
||||
pop %es
|
||||
|
||||
.entry:
|
||||
call serial_init
|
||||
|
||||
mov $msg, %si
|
||||
call prints
|
||||
|
||||
mov $12345678, %eax
|
||||
mov $10, %ecx
|
||||
call itoa
|
||||
|
||||
mov %ax, %si
|
||||
call prints
|
||||
.halt:
|
||||
jmp .halt
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue