From 5e7fe0db858e3af58d2b6bcc8fc68f400e848ad0 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Fri, 7 Oct 2022 00:00:23 -0700 Subject: [PATCH] Fix some cases with 0, and fix a label name --- bmi-calc/main.nasm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bmi-calc/main.nasm b/bmi-calc/main.nasm index 9136dc9..cec1288 100644 --- a/bmi-calc/main.nasm +++ b/bmi-calc/main.nasm @@ -84,7 +84,7 @@ good_height: syscall cmp r14,0 - je print_zero_bmi + je print_inf_bmi ; calculate bmi (kg/(m^2)) movq xmm1,r14 ; height @@ -118,7 +118,7 @@ exit: mov rax,SYS_exit syscall -print_zero_bmi: +print_inf_bmi: mov rax,SYS_write mov rdi,FD_stdout mov rsi,bmi_notice_text @@ -127,8 +127,8 @@ print_zero_bmi: mov rax,SYS_write mov rdi,FD_stdout - mov rsi,zero_float_text - mov rdx,zero_float_length + mov rsi,inf_float_text + mov rdx,inf_float_length syscall mov rax,SYS_write @@ -185,7 +185,7 @@ print_float_scale_loop: cvtss2si rax,xmm0 mov rcx,23 mov rbx,10 -print_float_reverse_loop: +print_float_mem_loop: xor rdx,rdx div rbx add rdx,'0' @@ -193,7 +193,7 @@ print_float_reverse_loop: dec rcx cmp rax,0 - jne print_float_reverse_loop + jne print_float_mem_loop push rcx push rdi @@ -398,6 +398,8 @@ period_char: db "." newline_char: db 0xA zero_float_text: db ".000" zero_float_length: equ $ - zero_float_text +inf_float_text: db "Infinity" +inf_float_length: equ $ - inf_float_text _10f: dd 10.0 _0.1f: dd 0.1 _100f: dd 100.0