📄 main2.asm
字号:
; Example assembly language program -- Ascending and Descending
; Author: zhudingfen
; Date: revised 8/08
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 使用 nmake 或下列命令进行编译和链接:
; ml /c /coff Main1.asm
; ml /c /coff Procedure1.asm
; link /debug /subsystem:console /entry:start /out:Main2.exe Main2.obj Procedure2.obj io.obj kernel32.lib
; Main1.exe
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
EXTRN Ascend:NEAR32 , Descend:NEAR32
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
INCLUDE io.h ; header file for input/output
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; line feed
.STACK 4096 ; reserve 4096-byte stack
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.DATA ; reserve storage for data
Suggest1 BYTE " Please input String : ", 0
Suggest2 BYTE " '0' Represent Descending and '1' Represent Ascending" ,cr , Lf ,"Please input Mode Flag: " , 0
Suggest3 BYTE "You input Flag error ,please input again: " , 0
sourceStr BYTE 100 DUP (?)
destStr BYTE 100 DUP (?)
flag BYTE ?
numberSpace DWORD ?
count DWORD ?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.CODE ; start of main program code
_start:
output Suggest1 ; prompt for source string
input sourceStr , 100 ; read ASCII characters
lea esi ,sourceStr
mov count , 0h
IfCmpSpace: ; Judge head of string wether space
cmp BYTE PTR [esi] , 20h
jne RemoveSpace
inc esi
inc count
jmp IfCmpSpace
RemoveSpace: ;remove head space
cmp count , 0h
je NoHeadSpace
mov ecx , count
lea edi , sourceStr
lea esi , sourceStr
add esi , count
Repeat1:
cmp BYTE PTR[esi] , 0h
je EndStr
mov al , [esi]
mov [edi] , al
inc edi
inc esi
jmp Repeat1
EndStr: ; if string head have space ,remove space ,and store it
mov BYTE PTR [edi] , 0h
inc edi
loop EndStr
NoHeadSpace:
lea esi , sourceStr
Repeat2: ;count space number
cmp BYTE PTR[esi] , 0h
je EndCount
cmp BYTE PTR [esi] , 20h
je Counter
inc esi
jmp Repeat2
Counter:
inc numberSpace
inc esi
jmp Repeat2
EndCount: ; input Mode flag: '0' Represent Descending and '1' Represent Ascending
output Suggest2
input flag , 1
ToJudge: ;Judge flag ,not '0' or '1' ,continue input
cmp flag , 30h
je SortDescend
cmp flag , 31h
je SortAscend
output Suggest3
input flag , 1
jmp ToJudge
SortDescend: ;access Descend Function
lea esi , sourceStr
mov edx , numberSpace
call Descend
jmp Exit
SortAscend: ;access Descend Function
lea esi , sourceStr
mov edx , numberSpace
call Ascend
Exit:
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -