kvisc/ka/crt/fmt/printf.k

63 lines
751 B
Plaintext
Raw Normal View History

2019-05-30 12:44:56 +02:00
; The OS/K Team licenses this file to you under the MIT license.
2019-05-29 19:05:06 +02:00
; See the LICENSE file in the project root for more information.
2019-05-22 18:39:46 +02:00
2019-05-29 18:26:28 +02:00
;
2019-06-17 20:59:30 +02:00
; int putc(int ch)
2019-05-29 18:26:28 +02:00
;
2019-06-17 20:59:30 +02:00
putc:
prn ax0
2019-09-07 16:45:03 +02:00
nul eax
2019-06-17 20:59:30 +02:00
ret
;
; int printf(const char *fmt, ...)
;
printf:
mov ax2, ax0
mov ax0, putc
mov ax1, STRLEN_MAX
2019-09-07 16:45:03 +02:00
add ax3, esp, 8
2019-06-19 13:50:53 +02:00
jmp doprnt
2019-05-29 18:26:28 +02:00
2019-07-01 13:16:17 +02:00
;
; int nprintf(const char *fmt, int n, ...)
;
nprintf:
mov ax2, ax0
mov ax0, putc
2019-09-07 16:45:03 +02:00
add ax3, esp, 8
2019-07-01 13:16:17 +02:00
jmp doprnt
2019-05-29 18:26:28 +02:00
;
; Print a string
2019-09-07 16:45:03 +02:00
; Guaranteed to only affect ecx and ax0
2019-05-29 18:26:28 +02:00
;
2019-05-29 16:57:22 +02:00
print:
2019-08-14 09:52:39 +02:00
.l:
2019-09-07 16:45:03 +02:00
movzx eax, b[ax0]
2019-09-08 19:04:07 +02:00
jeaxz .r
2019-08-14 09:52:39 +02:00
2019-09-07 16:45:03 +02:00
prn eax
2019-08-21 16:57:32 +02:00
inc ax0
2019-08-14 09:52:39 +02:00
jmp .l
.r:
2019-05-29 16:57:22 +02:00
ret
2019-05-29 18:26:28 +02:00
;
; Print exactly ax1 characters
;
2019-08-03 19:01:12 +02:00
nprint:
2019-09-07 16:45:03 +02:00
mov ecx, ax1
2019-09-08 19:04:07 +02:00
jecxz .r
2019-08-14 09:52:39 +02:00
.l:
prn b[ax0]
2019-08-21 16:57:32 +02:00
inc ax0
2019-08-14 09:52:39 +02:00
loop .l
2019-09-03 09:06:58 +02:00
2019-08-14 09:52:39 +02:00
.r:
2019-05-22 18:39:46 +02:00
ret