carlosrafaelgn/Asm86

print value of variable at console

Closed this issue · 2 comments

can you help me, how to print value of variable at console after summation of the variables value?

example:
MOV AL, NUM1 ; NUM1=15d
ADD AL, NUM2 ; NUM2=34d
ADD AL, NUM3 ; NUM3=56d

how i can print the total value in console? I'm very stuck even I refer the load example. Thank you!

can you help me sir?

Sorry for the delay... I don't access GitHub very often... :(

mov eax, 1234
; we must know the amount of characters we will write before starting (sign is not being handled)
mov ecx, 10
mov ebx, 0
_count:
mov edx, 0
div ecx
inc ebx
test eax, eax
jnz _count

shl ebx, 1 ; the console needs unicode characters (1 character = 2 bytes)
lea edi, [formattedNumber + ebx] ; formattedNumber is a 32-byte long variable, to hold the text
mov ax, 0
mov [edi], ax ; terminate the string with a null character
sub edi, 2

mov eax, 1234 ; now we perform the actual conversion
mov ecx, 10
_LOOP:
mov edx, 0
div ecx ; edx is the remainder of the division by 10
add dx, 0x30 ; 0x30 = character 0
mov [edi], dx
sub edi, 2
test eax, eax
jnz _LOOP

mov ax, 0x0000 ; move the cursor to 0,0
out 0xEA, ax
lea eax, formattedNumber
out 0xEC, eax ; pointer where to take the characters from
mov al, 16
out 0xE6, al ; print up to 16 characters (the null character make the process stop sooner than that)
mov al, 3
out 0xE8, al ; sends the text pointed by 0xEC to console's memory (a 0 character stops the process, even if the value at 0xE6 is greater)
mov al, 4
out 0xE8, al ; update the contents of the entire screen at once