Print answers in decimal in apps/arith.mu
This commit is contained in:
Kartik Agaram 2020-09-14 21:14:04 -07:00
parent 40d40b83de
commit 6b41ca6d95
5 changed files with 56 additions and 9 deletions

View File

@ -223,6 +223,37 @@ $print-int32-hex-to-real-screen:end:
5d/pop-to-ebp
c3/return
print-int32-decimal-to-real-screen: # n: int
# . prologue
55/push-ebp
89/<- %ebp 4/r32/esp
#
(write-int32-decimal-buffered Stdout *(ebp+8))
(flush Stdout)
$print-int32-decimal-to-real-screen:end:
# . epilogue
89/<- %esp 5/r32/ebp
5d/pop-to-ebp
c3/return
write-int32-decimal-buffered: # f: (addr buffered-file), n: int
# . prologue
55/push-ebp
89/<- %ebp 4/r32/esp
# var ecx: (stream byte 16)
81 5/subop/subtract %esp 0x10/imm32
68/push 0x10/imm32/size
68/push 0/imm32/read
68/push 0/imm32/write
89/<- %ecx 4/r32/esp
(write-int32-decimal %ecx *(ebp+0xc))
(write-stream-data *(ebp+8) %ecx)
$write-int32-decimal-buffered:end:
# . epilogue
89/<- %esp 5/r32/ebp
5d/pop-to-ebp
c3/return
reset-formatting-on-real-screen:
# . prologue
55/push-ebp

2
400.mu
View File

@ -146,6 +146,8 @@ sig print-string-to-real-screen s: (addr array byte)
sig print-stream-to-real-screen s: (addr stream byte)
sig print-grapheme-to-real-screen c: grapheme
sig print-int32-hex-to-real-screen n: int
sig print-int32-decimal-to-real-screen n: int
sig write-int32-decimal-buffered f: (addr buffered-file), n: int
sig reset-formatting-on-real-screen
sig start-color-on-real-screen fg: int, bg: int
sig start-bold-on-real-screen

View File

@ -439,6 +439,21 @@ $print-int32-hex:body: {
}
}
fn print-int32-decimal screen: (addr screen), n: int {
$print-int32-decimal:body: {
compare screen, 0
{
break-if-!=
print-int32-decimal-to-real-screen n
break $print-int32-decimal:body
}
{
break-if-=
# fake screen
}
}
}
fn reset-formatting screen: (addr screen) {
$reset-formatting:body: {
compare screen, 0

View File

@ -4,7 +4,6 @@
# https://compilers.iecc.com/crenshaw
#
# Limitations:
# Reads numbers in decimal, but prints numbers in hex :(
# No division yet.
#
# To build:
@ -14,19 +13,19 @@
# $ ./a.elf
# press ctrl-c or ctrl-d to exit
# > 1
# 0x00000001
# 1
# > 1+1
# 0x00000002
# 2
# > 1 + 1
# 0x00000002
# 2
# > 1+2 +3
# 0x00000006
# 6
# > 1+2 *3
# 0x00000007
# 7
# > (1+2) *3
# 0x00000009
# 9
# > 1 + 3*4
# 0x0000000d
# 13
# > ^D
# $
#
@ -46,7 +45,7 @@ fn main -> exit-status/ebx: int {
compare look, 0
break-if-=
# print
print-int32-hex 0, n
print-int32-decimal 0, n
print-string 0, "\n"
#
loop

BIN
apps/mu

Binary file not shown.