Print number of sectors

This commit is contained in:
Alex Kotov 2022-01-27 05:47:11 +05:00
parent 2d8836ccdc
commit f208a2aa6d
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 38 additions and 0 deletions

View File

@ -37,6 +37,7 @@ newline: .string "\r\n"
hello: .string "Hello from stage 1!\r\n"
stage1_size_str: .string "Stage 1 size: "
stage2_size_str: .string "Stage 2 size: "
number_of_sectors: .string "Number of sectors: "
main:
cli
@ -70,6 +71,26 @@ main:
mov (%bx), %ax
call print_size
// DX - dividend high (always zero)
xor %dx, %dx
// AX - dividend low
mov $STAGE2_ADDR(size), %bx
mov (%bx), %ax
// BX - divisor (always 512)
mov $512, %bx
// AX - quotient
// DX - remainder
div %bx
test %dx, %dx
jz no_rem
inc %ax
no_rem:
// AX - number of sectors
push %ax
call print_number_of_sectors
pop %ax
ljmp $0, $STAGE2_BASE
hang:
@ -144,4 +165,19 @@ print_size:
ret
// AX - number of sectors
print_number_of_sectors:
push %ax
mov $STAGE1_ADDR(number_of_sectors), %si
call print_str
pop %ax
call print_number
mov $STAGE1_ADDR(newline), %si
call print_str
ret
_end:

View File

@ -61,4 +61,6 @@ print_str:
call print_char
jmp print_str
.fill 512, 1, 0
_end: