[OS]miniOS-3(2)

✔️ sector2.asm

— 두번째 섹터 / Second sector

[org 0x8000]

1)컴파일러는 이 값을 기준으로 모든 문자열 주소(예: msg_next_sector)의 위치를 계산합니다.
The compiler calculates the locations of all string addresses (e.g., msg_next_sector) based on this value.

2)PC가 처음 부팅되었을 때, 16비트 리얼 모드에서 사용할 수 있는 기본 메모리 맵(약 640KB) 중 사용자가 마음대로 쓸 수 있는 안전한 구간이 존재합니다.
When a PC first boots up, there is a safe region within the base memory map (approximately 640 KB) available in 16-bit real mode that the user can utilize freely.

3)그래서 주소를 0x9000으로 바꿀 수 있습니다.
So, you can change the address to 0x9000.

0x0000 ~ 0x04FF: 
BIOS 인터럽트 벡터 테이블, BIOS 데이터 영역 (절대 건드리면 안 됨)
BIOS Interrupt Vector Table, BIOS Data Area (must absolutely not be touched)

0x7C00 ~ 0x7DFF: 
MBR 코드가 로드되는 영역 (512바이트)
The area where the MBR code is loaded (512 bytes)

0x7E00 ~ 0x9FFFF: 
비어 있는 일반 메모리 영역 (자유롭게 사용 가능)
Unused general memory area (available for free use)

— 16비트 리얼모드 / 16bit real mode

bits 16

— mov si, msg_boot 여기 si레지스터에 msg_next_sector에 저장된 값의 주소를 저장합니다.
mov si, msg_boot: This stores the address of the value held in msg_next_sector into the si register.

mov si, msg_next_sector

— print_string라벨 함수 호출입니다.
This is a call to the print_string_label function.

call print_string

— 대기모드입니다.(자기 자신의 위치로 점프합니다.)
It is in standby mode. (It jumps to its own position.)

jmp $

— 메모리에 저장된 문자열을 한 글자씩 읽어서, 화면에 연속으로 출력하는 함수입니다.
This function reads a string stored in memory character by character and outputs it to the screen continuously.

print_string:
    lodsb
    cmp al, 0
    je .done
    mov ah, 0x0e
    int 0x10
    jmp print_string
.done:
    ret

— 변수를 선언부분입니다.
This is the section where variables are declared.

1)각 변수에 문자를 1바이트씩 저장합니다.
Store one byte of character data in each variable.

2)13은 캐리지 리턴(\r)으로 커서를 현재 줄의 맨 왼쪽(첫 번째 칸)으로 이동시킵니다.
13 is the carriage return (\r), which moves the cursor to the far left (the first column) of the current line.

3)10 라인 피드(\n)로 커서를 현재 위치에서 정확히 한 줄 아래로 내립니다.
10 Moves the cursor exactly one line down from its current position using a line feed (\n).

msg_next_sector db '3. Hello from Sector 2 (0x8000)!', 13, 10, 0

— 계산된 횟수만큼 바이트(db) 공간을 전부 0으로 채우라는 명령어입니다.
This command fills the specified number of bytes (db) with zeros.

1)부팅판별을 위한 시그니처가 필요 없기 때문에 512입니다.
It is 512 because no signature is required to determine the boot status.

times 512 - ($ - $$) db 0

Leave a Reply