-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.asm
More file actions
60 lines (51 loc) · 1.72 KB
/
kernel.asm
File metadata and controls
60 lines (51 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
GLOBAL k_printstr
k_printstr:
; void k_printstr(char *s, int row, int col)
; set up abp so we can get to the argument s , row and col
push ebp
mov ebp, esp
; now push any registers you may use during the function, including the flags register
pushf
push eax
push ebx
; and so on
; now load row and col into eax and ebx
mov eax, [ebp+12]
mov ebx, [ebp+16]
; calculate the offset into video memory using row and col
; (offset = (row * 80 + col) * 2)
imul eax, 80
add eax, ebx
imul eax, 2
; calculate the absolute address of video memory for storing
; the next character by adding 0xB8000 and the offset
add eax, 0xB8000
mov edi, eax
; now load the address of the string into esi
mov esi, [ebp+8]
;if the address where to write the next character has passed the end of video memory (0xB8000+80*25*2) then
mov eax, 80
imul eax, 25
imul eax, 2
add eax, 0xB8000
print_again: ;loop
cmp edi, eax
jge loop_end ;go to loop_end
cmp BYTE [esi], 0 ;if string address poins to 0 byte then
je loop_end ;go to loop_end
; mov the next character from the string into video memory
; and increment the string address and the address where to
; write the next character (can be done in one instruction: movsb)
movsb ; move the byte at esi to edi
; mov a color byte into the video memory
mov BYTE [edi], 31 ;move a color byte say 31, into the memory at edi
;increment the address where to write the next character
inc edi ; to point to the next character in memory
jmp print_again
loop_end:
; clean up and return to the caller
pop ebx
pop eax
popf
pop ebp
ret ;return