Fix some cases with 0, and fix a label name
This commit is contained in:
		@ -83,6 +83,9 @@ good_height:
 | 
				
			|||||||
    mov rdx,height_notice_post_length
 | 
					    mov rdx,height_notice_post_length
 | 
				
			||||||
    syscall
 | 
					    syscall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cmp r14,0
 | 
				
			||||||
 | 
					    je print_inf_bmi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ; calculate bmi (kg/(m^2))
 | 
					    ; calculate bmi (kg/(m^2))
 | 
				
			||||||
    movq xmm1,r14 ; height
 | 
					    movq xmm1,r14 ; height
 | 
				
			||||||
    divss xmm1,[_100f] ; cm to m
 | 
					    divss xmm1,[_100f] ; cm to m
 | 
				
			||||||
@ -110,11 +113,32 @@ good_height:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    call clear_stdin
 | 
					    call clear_stdin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ; exit
 | 
					exit:
 | 
				
			||||||
    xor rdi,rdi
 | 
					    xor rdi,rdi
 | 
				
			||||||
    mov rax,SYS_exit
 | 
					    mov rax,SYS_exit
 | 
				
			||||||
    syscall
 | 
					    syscall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print_inf_bmi:
 | 
				
			||||||
 | 
					    mov rax,SYS_write
 | 
				
			||||||
 | 
					    mov rdi,FD_stdout
 | 
				
			||||||
 | 
					    mov rsi,bmi_notice_text
 | 
				
			||||||
 | 
					    mov rdx,bmi_notice_length
 | 
				
			||||||
 | 
					    syscall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    mov rax,SYS_write
 | 
				
			||||||
 | 
					    mov rdi,FD_stdout
 | 
				
			||||||
 | 
					    mov rsi,inf_float_text
 | 
				
			||||||
 | 
					    mov rdx,inf_float_length
 | 
				
			||||||
 | 
					    syscall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    mov rax,SYS_write
 | 
				
			||||||
 | 
					    mov rdi,FD_stdout
 | 
				
			||||||
 | 
					    mov rsi,newline_char
 | 
				
			||||||
 | 
					    mov rdx,1
 | 
				
			||||||
 | 
					    syscall
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    jmp exit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
clear_stdin:
 | 
					clear_stdin:
 | 
				
			||||||
    ; 16 - read buff
 | 
					    ; 16 - read buff
 | 
				
			||||||
    ; 4 - pollfd.fd
 | 
					    ; 4 - pollfd.fd
 | 
				
			||||||
@ -146,6 +170,10 @@ clear_stdin_end:
 | 
				
			|||||||
    ret
 | 
					    ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print_float: ; void print_float(float f, int percission)
 | 
					print_float: ; void print_float(float f, int percission)
 | 
				
			||||||
 | 
					    movq rax,xmm0
 | 
				
			||||||
 | 
					    cmp rax,0
 | 
				
			||||||
 | 
					    je print_float_zero
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sub rsp,24
 | 
					    sub rsp,24
 | 
				
			||||||
    movss xmm1,[_10f]
 | 
					    movss xmm1,[_10f]
 | 
				
			||||||
    mov rcx,rdi
 | 
					    mov rcx,rdi
 | 
				
			||||||
@ -157,7 +185,7 @@ print_float_scale_loop:
 | 
				
			|||||||
    cvtss2si rax,xmm0
 | 
					    cvtss2si rax,xmm0
 | 
				
			||||||
    mov rcx,23
 | 
					    mov rcx,23
 | 
				
			||||||
    mov rbx,10
 | 
					    mov rbx,10
 | 
				
			||||||
print_float_reverse_loop:
 | 
					print_float_mem_loop:
 | 
				
			||||||
    xor rdx,rdx
 | 
					    xor rdx,rdx
 | 
				
			||||||
    div rbx
 | 
					    div rbx
 | 
				
			||||||
    add rdx,'0'
 | 
					    add rdx,'0'
 | 
				
			||||||
@ -165,7 +193,7 @@ print_float_reverse_loop:
 | 
				
			|||||||
    dec rcx
 | 
					    dec rcx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cmp rax,0
 | 
					    cmp rax,0
 | 
				
			||||||
    jne print_float_reverse_loop
 | 
					    jne print_float_mem_loop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    push rcx
 | 
					    push rcx
 | 
				
			||||||
    push rdi
 | 
					    push rdi
 | 
				
			||||||
@ -202,6 +230,13 @@ print_float_reverse_loop:
 | 
				
			|||||||
    add rsp,24
 | 
					    add rsp,24
 | 
				
			||||||
    ret
 | 
					    ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print_float_zero:
 | 
				
			||||||
 | 
					    mov rax,SYS_write
 | 
				
			||||||
 | 
					    mov rdi,FD_stdout
 | 
				
			||||||
 | 
					    mov rsi,zero_float_text
 | 
				
			||||||
 | 
					    mov rdx,zero_float_length
 | 
				
			||||||
 | 
					    syscall
 | 
				
			||||||
 | 
					    ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; on error, return 0 in rax. otherwise, return 1 in rax 
 | 
					; on error, return 0 in rax. otherwise, return 1 in rax 
 | 
				
			||||||
; and the result in xmm0
 | 
					; and the result in xmm0
 | 
				
			||||||
@ -361,6 +396,10 @@ size_error_text: db "Number too long!",0xA
 | 
				
			|||||||
size_error_length: equ $ - size_error_text
 | 
					size_error_length: equ $ - size_error_text
 | 
				
			||||||
period_char: db "."
 | 
					period_char: db "."
 | 
				
			||||||
newline_char: db 0xA
 | 
					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
 | 
					_10f: dd 10.0
 | 
				
			||||||
_0.1f: dd 0.1
 | 
					_0.1f: dd 0.1
 | 
				
			||||||
_100f: dd 100.0
 | 
					_100f: dd 100.0
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user