From news.csie.nctu.edu.tw!tsaiwn Sun Nov 6 09:57:11 1994 Path: news.csie.nctu.edu.tw!tsaiwn From: tsaiwn@csie.nctu.edu.tw (Wen-Nung Tsai) Newsgroups: csie.course.asm.a,csie.course.asm.b Subject: source of HELLO.COM Date: 4 Nov 1994 15:09:27 GMT Organization: Dep. Computer Sci. & Information Eng., Chiao Tung Univ., Taiwan, R.O.C Lines: 67 Message-ID: <39dir7$bls@news.csie.nctu.edu.tw> NNTP-Posting-Host: tsaiwn@bbs.csie.nctu.edu.tw X-Newsreader: TIN [version 1.2 PL2] Xref: news.csie.nctu.edu.tw csie.course.asm.a:67 csie.course.asm.b:179 To make the following code usable, save this article into a file and then use "vi" to remove the line numbers: :1,$s/^.......// (這regular expression 共有七個點) :wq Here it is: 1 Title HWK03 - the source program 2 assume cs:mycode,ds:mycode 3 mycode segment public 4 ORG 100h ; for .COM format 5 Main proc near 6 JMP short GO ; only for first RUN 7 ; in .COM, the data in program is not it's original form 8 ;===================== 9 ; Linkage instruction: 10 ; MASM file; 11 ; LINK file; 12 ; DEBUG file.exe 13 ; - g 14 ; -n file.com ; specify NAME to write 15 ; -w 16 ; -q ; quit 17 ;=============== another way after LINK file; 18 ; EXE2BIN file file.com (or LINK /tiny directly...) 19 ; DEBUG file.com 20 ; -g ; go 21 ; -w ; write back to file.com 22 ; -q ; it's done 23 ;=============== 24 MOV AL,[MAGIC] ; a magic number 25 MOV AH,0eh ; write as teletype 26 MOV CX,LENMSG ; Length of MSG as loop count 27 LEA SI,MSG 28 AGAIN: 29 XOR AL,CS:[SI] 30 INT 10h ; to screen 31 INC SI ; next char 32 LOOP AGAIN ; repeat until done(cx=0) 33 MOV AX,4c00h ; normal terminate 34 INT 21h ; Bye 35 MAGIC DB 38h 36 MSG DB 'Hello from Wen-Nung Tsai',10,13 37 LENMSG = $ - MSG ; the length of the above STRING 38 GO: 39 MOV ax,9090h ; NOP / NOP 40 MOV WORD PTR CS:[MAIN],AX ; erase the JMP short GO 41 LEA SI,MSG+LENMSG ; Si points to the last byte of MSG 42 MOV CX,LENMSG ; Loop Count 43 AGAIN2: 44 DEC SI ; backword 45 MOV AL,CS:[SI] ; Encode the data 46 XOR AL,CS:[SI-1] ;... 47 MOV Byte PTR CS:[SI],AL 48 LOOP AGAIN2 49 MOV CX,GO - Main ; the .COM program length 50 ;..so that we can "w" into a file in DEBUG 51 INT 3 ; used in debug only 52 main endP 53 mycode endS 54 END MAIN -- -------------------------------------------- Wen-Nung Tsai 蔡文能 INTERNET: tsaiwn@csunix.csie.nctu.edu.tw Dep. of CSIE BITNET: tsaiwn@twnctu01.bitnet National Chiao Tung University HsinChu, Taiwan, R.O.C.