用汇编语言如何编译一个程序

来源:百度知道 编辑:UC知道 时间:2024/05/28 22:53:02
用汇编语言编译一个程序,显示一个时间日期的程序
A.在屏幕上显示系统日期
B.在屏幕中央以红底白字显示系统日期

工具:nasm MinGW-gcc, WINDOWS
echo_current_time.asm
////////////////////////////////////////////////////////////

extern _printf,_ctime,_time
section .text

global _main
_main:
push ebp
mov ebp, esp
mov ebx, 0
sub esp,4
mov [ebp-4], dword 0
mov ebx,0
push ebx
call _time
add esp,4

mov [ebp-4],dword eax

lea ebx,[ebp-4]
push ebx
call _ctime
add esp,4

push eax
push dword fmtmsg
call _printf
add esp,8

leave
ret

section .data
fmtmsg: db "current time: %s",13,10,0

#nasm -fwin32 -oecho_current_time.o echo_current_time.asm
#gcc -o echo_current_time echo_current_time.o
#echo_current_time
current time: Sat Nov 29 19:17:54 2008

正文如下(复制虚线内文本,粘贴到rq.txt):
------------------------------------
a100
PUSH CS
POP DS