编写两个汇编语言子程序,分别返回系统的当前日期和时间,编写一个C语言程序,调用这两个汇编语言子程序,显示系统的当前日期和时间。
程序运行时显示的信息格式为:
Current date is 10-30-2001. Current time is 10:23:26.12
我的实现如下,为什么不能编译,我已经在VC工程那link了obj文件:
#include <stdio.h>
#include <iostream.h>
extern "C " int get();
int main()
{
get();
return 0;
}
汇编子程序:(单独执行能够成功)
;========================================== ;get.asm
;A little assembly app that shows the current date and time.
;It can be done a lot easier, but this way you will
;see how to do some basic memory manipulation, and how to use 'variables '.
;==========================================
.model small
.stack
;===========================
;Data segment starts here
;===========================
.data
date_str DB "Current date is: yyyy-mm-dd ", 0Ah, 0Dh, "$ "
time_str DB "Current time is: hh.mm.ss:xx ", 0Ah, 0Dh, "$ "
min_size DW ?
padd_chr DB ?
;===========================
;Code segment starts here
;===========================
.code
PUBLIC _get
;main
_get PROC
MOV AX, SEG @data ;First we get the data segment address
MOV DS, AX ;and store it into ds
MOV [min_size], 02h ;Results should always be at least two digits
MOV [padd_chr], '0 ' ;Use '0 ' as padding-character
MOV AH, 2Ah ;Then we call int 21h,2Ah, which will give
INT 21h ;us the current date
LEA DI, date_str ;Then we load the address of the date_str string
ADD DI, 17 ;and set si to point at the first y in yyyy-...
MOV AX, CX ;Next we mov cx to ax and
CALL todec ;call todec
INC DI ;We skip the '- ' character...
XOR AX, AX ;Then we empty ax
MOV AL, DH ;And set the low-byte of ax to dh
CALL todec
INC DI ;Skip character in string...
XOR AX, AX ;Empty ax
MOV AL, DL ;Set low-byte to dl