Write a program that turns a 32-bit numeric value (e.g., 0xFFFFh) and converts it to a byte array such that it can be printed to the screen using a system call method. A loop is necessary for converting the numeric value to ASCII for output. Again, use a system call (e.g., int 80h) to print the value to the console (see "Course Material" -> Examples). Calling external functions (e.g. printf) is not allowed.

Respuesta :

Answer:

The program is written below,

.386

.MODEL FLAT, stdcall

.STACK 4096

GetStdHandle PROTO, nStdHandle:DWORD

WriteConsoleA PROTO,

hConsoleOutput:DWORD, ; output handle

lpBuffer:PTR BYTE, ; pointer to buffer

nNumberOfCharsToWrite:DWORD, ; size of buffer

lpNumberOfCharsWritten:PTR DWORD, ; num bytes written

lpReserved:DWORD ; not used (NULL)

ExitProcess PROTO, dwExitCode:DWORD

.data

bytesWritten DWORD 0 ; for WriteConsoleA

stdHandle DWORD 0 ; for WriteConsoleA

s1 BYTE "Hello Universe", 13, 10, 0

lenS1 = ($ - s1)

.code

_main PROC

print:

; get STDOUT handle

push -11 ; request STD_OUTPUT_HANDLE (-11)

call GetStdHandle ; call WinAPI to get console handle

mov stdHandle, eax ; save stdHandle

push 0 ; reserved, push NULL

push OFFSET bytesWritten ; bytes written

mov eax, lenS1

push eax ; bytes to write

push OFFSET s1 ; string address

push stdHandle ; STD_OUPUT_HANDLE

call WriteConsoleA ; call win api to write text to console

done:

INVOKE ExitProcess, 0

_main ENDP

END

ACCESS MORE
EDU ACCESS