Create a macro to print a digit stored in rax to the console. This macro should also have error handling to display an error messsage to the console if the value in rax is not really a digit(from 0 to 9)?
Macro, I created in separate file
%macro digitPrinter 2
section .data
text1 db "You entered a digit",10,0
size1 equ $-text1
text2 db "Not a digit",10,0
size2 equ $-text2
mov rax,4
mov rbx,1
mov rcx, %1
mov rdx, %2
int 128
mov rbx, [%1]
cmp rbx, '9'
jle check_more
Not_digit:
call textPrinter2
call exit
check_more:
cmp rbx,48
jl Not_digit
call textPrinter1
call exit
textPrinter1:
mov rax,4
mov rbx,1
mov rcx, text1
mov rdx, size1
int 128
ret
textPrinter2:
mov rax,4
mov rbx,1
mov rcx, text2
mov rdx, size2
int 128
ret
exit :
mov rax,1
mov rbx,0
int 128
ret
%endmacro
Then I include this file in main .asm file
%include "PrintDigit_3129.inc"
section .data
section .bss
result resb 1
section .text
global _start
_start:
mov rax,'5'
mov [result],rax
digitPrinter result,1
Programme execute perfectly using make utility but it gives run time error, "Segmentation fault(core dumped)" I think this may be due to issue in macro when accessing address of memory, I tried few times I can not fix this issue.