저는 최근에 운영 체제, 부팅 프로세스 및 NASM을 연구했습니다. 필자는 필자가 부분적으로 이해하고 가상 플로피 디스크를 통해 테스트 한 유용한 부트 스트랩 핑 코드를 발견했다. 내 기본적인 질문은 내가 이해하지 못하는 몇 가지 사항에 관한 것입니다. 내가 생각하기에 선이하는 일에 대해 의견을 말했고, 모든 수정이나 확인은 크게 감사 할 것입니다. ah
세트까지 화면에 al
의 문자를 인쇄 할 int 10h
기능 Teletype output,에기본 NASM 부트 스트랩
; This is NASM
BITS 16 ; 16 bits!
start: ; Entry point
mov ax, 07C0h ; Move the starting address (after this bootloader) into 'ax'
add ax, 288 ; Leave 288 bytes before the stack beginning for some reason
mov ss, ax ; Show 'stack segment' where our stack starts
mov sp, 4096 ; Tell 'stack pointer' that our stack is 4K in size
mov ax, 07C0h ; Use 'ax' as temporary variable for setting 'ds'
mov ds, ax ; Set data segment to where we're loaded
mov si, text_string ; Put string position into SI (the reg used for this!)
call print_string ; Call our string-printing routine
jmp $ ; Jump here - infinite loop!
text_string db 'This is my cool new OS!', 0 ; Our null terminated string
; For some reason declared after use
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; I don't know what this does..
; Continue on to 'repeat'
.repeat:
lodsb ; Get character from DS:SI into AL
cmp al, 0 ; If end of text_string
je .done ; We're done here
int 10h ; Otherwise, print the character (What 10h means)
jmp .repeat ; And repeat
.done:
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC 'magic word' boot signature
감사합니다,
조
아, 그래서 4608 바이트가 실제로 '도끼'에 추가되고 있습니다. . 아마도이 중 512 개는 스크립트/프로그램 자체를위한 것이고, 그 중 4096 개는 무언가에 사용됩니다. 4096은 디스크 버퍼로 사용 되는가 스택 자체를위한 것인가? 스택의 시작이나 끝으로 'ss'가 설정되어 있습니까? –
@ Joesavage1 SS는 스택의베이스를 정의하고 SP는 스택에있는 위치를 정의합니다. 스택이 비어 있으면 SP는 SS에서 가장 높은 오프셋을 가리 킵니다. 즉, 물건이 스택에 푸시되고 튀어 나올 때 점진적으로 증가하면 SP가 실제로 감소합니다.SP 항상 스택에 푸시 된 마지막 항목을 가리킴 – Dougvj
스택의 _start_를 나타냅니다. 그렇다면 왜 코드 자체의 저장 위치에서 4096 바이트 떨어진 위치 ('도끼')를 전달할 수 있습니까? (사물의 진입 지점에서 4608) 그들이 스택을위한 것이 아닌 경우의 4096 바이트는 무엇입니까? 또한, 왜 'ds'가 스택 작업이 완료된 후에 07C0h [7C00h]로 다시 설정되는지 알 수 있습니까? ("데이터 세그먼트를로드하는 위치로 설정하십시오") –