;nasm -fbin PrintInt.asm -o PrintInt.comorg 100hsegment .textpushamov EAX, 5473 ;save our interger to EAXcall print_int ;call print_int routinepopamov EAX, 4C00h ;instruct to exit programint 21hsegment .textprint_int:pusha ;push all registers to the stackmov ECX, 0countDigits:cdq ;This instruction is available only ;on the 80386 and latermov EBX, 10idiv EBX ;divide EAX by EBX, ;the result is saved as: EAX:EDXpush EDX ;save the fractional part of ;the fraction above in the stack. ;the digits of our integer are saved ;like this: 3, 7, 4, 5inc ECX ;increament ECX, it tracks the number ;of digits in our integercmp EAX, 0jnz countDigits ;when EAX is 0 means we had pushed ;every digit of our integer to ;the stackshow_int:pop EDX ;retrive the saved digits on the ;stack and load them to EDX. ;our digits are retrived from the ;stack in this order: 5, 7, 4, 3 ;remember Last In First Out.add EDX, 30h ;convert our retrived digt to asciimov AH, 2h ;2h is an interrupt when passed to AH ;that instruct the processor to print ;to standart output the ascii value ;saved in EDX.int 21h ;instruct the processor to execute ;the interrupt above.dec ECX ;at this point we have one less digit ;to display.cmp ECX, 0jnz show_intpopa ;retrive the register values that been ;pushed to the stack with "pusha"ret ;return
mov byte [Var], 5xor EAX, EAXmov AL, byte [Var]call print_int
;nasm -fbin PrintString.asm -o PrintString.comorg 100hsegment .textmov EAX, msgcall print_stringmov AX, 4C00hint 21hsegment .textprint_string:pushamov EDX, EAXmov AH, 9h ;if you move 9h to AL ;the prog will hang for ;user inputint 21hpoparetsegment .datamsg DB 'Hello, I am an Assembly Programmer:D', 24h
mov EDX, EAXmov AH, 9h ;if you move 9h to AL ;the prog will hang for ;user inputint 21h
I question the comment in this section:Code: [Select]mov EDX, EAXmov AH, 9h ;if you move 9h to AL ;the prog will hang for ;user inputint 21hDoes this actually work for you?Best,Frank