修改一个Keil的例子程序来收尾,
HelloWorld是不是你们编写的第一个程序?
第一个汇编语言, 主程序, 输出HelloWorld
NAME SAMPLE
EXTRN CODE (PUT_CRLF, PUTSTRING)
PUBLIC TXTBIT
PROG SEGMENT CODE
CONST SEGMENT CODE
VAR1 SEGMENT DATA
BITVAR SEGMENT BIT
STACK SEGMENT IDATA
RSEG STACK
DS 10H ; 16 Bytes Stack
CSEG AT 0
USING 0 ; Register-Bank 0
; Execution starts at address 0 on power-up.
JMP START
RSEG PROG
; first set Stack Pointer
START: MOV SP,#STACK-1
; Initialize serial interface
; Using TIMER 1 to Generate Baud Rates
; Oscillator frequency = 11.059 MHz
MOV TMOD,#00100000B ;C/T = 0, Mode = 2
MOV TH1,#0FDH
SETB TR1
MOV SCON,#01010010B
; clear TXTBIT to read form CODE-Memory
CLR TXTBIT
; This is the main program. It is a loop,
; which displays the a text on the console.
REPEAT:
; type message
MOV DPTR,#TXT
CALL PUTSTRING
CALL PUT_CRLF
; repeat
SJMP REPEAT
;
RSEG CONST
TXT: DB 'Hello World!',00H
; only for demonstration
RSEG VAR1
DUMMY: DS 21H
; TXTBIT = 0 read text from CODE Memory
; TXTBIT = 1 read text from XDATA Memory
RSEG BITVAR
TXTBIT: DBIT 1
END
第二个文件,串口IO
NAME CHAR_IO
;
PUBLIC PUTCHAR
CHAR_ROUTINES SEGMENT CODE
VAR2 SEGMENT DATA
RSEG CHAR_ROUTINES
; This routine outputs a single character to console.
; The character is given in A.
PUTCHAR:
JNB TI,$
CLR TI
MOV SBUF,A
RET
; only for demonstration
RSEG VAR2
DUMMY: DS 40H
END
第三个文件, String IO
NAME STRING_IO
;
EXTRN BIT (TXTBIT)
EXTRN CODE (PUTCHAR)
PUBLIC PUT_CRLF, PUTSTRING
STRING_ROUTINES SEGMENT CODE
RSEG STRING_ROUTINES
; This routine outputs a CR and a LF
CR equ 0DH ; carriage return
LF equ 0AH ; line feed
PUT_CRLF:
MOV A,#CR
CALL PUTCHAR
MOV A,#LF
CALL PUTCHAR
RET
; Routine outputs a null-terminated string whose
; address is given in DPTR. The string can be
; located in CODE or XDATA memory depending on
; the value of TXTBIT.
PUTSTRING:
; check TXTBIT
JB TXTBIT,PS1
CLR A
MOVC A,@A+DPTR
SJMP PS2
PS1: MOVX A,@DPTR
PS2: JZ EXIT
CALL PUTCHAR
INC DPTR
SJMP PUTSTRING
EXIT: RET
END
|