⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 looptest.asm

📁 从键盘输入一个字符串,先把它原样显示一遍 然后将其中的小写字母转换为大写显示,再将其中的大写字母转换为小写显示,最后将其中的大小写字母互换显示.显示字符串的功能调用采用宏,大写转换,小写转换和大小写互
💻 ASM
字号:
whpointer = 0
whcounter=0
res=0
Ifpointer=0
Ifcounter=0

combin macro x1,x2
res=x1&x2
endm   

jump macro x1,x2
	jmp x1&x2&
	endm

wLabeling macro top
    wlabel_&top&:
    endm
    
iLabeling macro top
    ILabel_&top&:
endm
  
Wh_asign macro top,value
     wh_s&top=value
endm
         
Wh_push  macro x1
	whpointer=whpointer+1
    whcounter = whcounter+1
    Wh_asign %whpointer,%whcounter
endm
         
Wh_pop  macro
     whpointer=whpointer-1
endm

If_asign macro top,value
     If_s&top=value
endm

If_push  macro x1
	Ifpointer=Ifpointer+1
    IfCounter = IfCounter+1
    If_asign %Ifpointer,%IfCounter
endm
         
If_pop  macro
     Ifpointer=Ifpointer-1
endm
;------------------------------
_While macro x1,op,x2;;
Local next    
   Wh_push   ;; whpointer=n+1,counter=m+1,sn+1=m+1 
   Wh_push   ;; whpointer=n+2,counter=m+2,sn+2=m+2
   Sptmp=whpointer-1 ;; sptmp=n+2-1=n+1
wLabeling %sptmp  ;; label_%sn+1 -> label_m+1:
   Cmp x1,x2
   j&op next; jop next 
   combin wh_s,%whpointer
   jump wLabel_,%res
Next:
endm

_Wend macro
   sptmp=whpointer-1    ;;sptmp=n+2-1=n+1
   combin wh_s,%sptmp
   jump wLabel_,%res
wLabeling %whpointer  ;label_%sn+2: -〉label_m+2:
   Wh_pop              ;;whpointer=n+1
   Wh_pop              ;;whpointer=n
endm
;-----------------------------------------
_If macro x1,op,x2
	local next
	If_push
	If_push
	cmp x1,x2
	j&op next
	sptmp=Ifpointer-1
	combin If_s,%sptmp
	jump ILabel_,%res
next:
endm

_Else macro
	sptmp=Ifpointer-1
	combin If_s,%Ifpointer
	jump ILabel_,%res
	iLabeling %sptmp
endm

_Ifend macro
	sptmp=Ifpointer-1
	ifndef iLabeling %sptmp
			iLabeling %sptmp
	endif
	iLabeling %Ifpointer
	If_pop
	If_pop
endm
;-----------------------------------------------
data segment
input db 'please input a number to loop',0dh,0ah,'$'
num   dw 0
data ends

code segment
			assume cs:code,ds:data
main proc far

start: 
  mov ax,data
	mov ds,ax
	call decibin ;
	mov cx,1
	_While cx,le,bx
			mov si,1
			
	_While si,le,cx
			mov ax,si
			and ax,01h ;与运算
			_If ax,e,01; 奇偶判断
			mov dx,'1'
			mov ah,02h
			int 21h
			_Else
			mov dx,'0'
			mov ah,02h
			int 21h
			_Ifend
			mov dx,20h
			mov ah,02h
			int 21h
			inc si
		_Wend
	
	inc cx
	call crlf
	_Wend
	
	
	main endp
	
;-------------------
;从键盘取得十进制数并把它转换成二进制数,并放置在BX中
decibin proc  near
	mov bx,0  
	;清bx,用来放输入数字得到的二进制数

decibin_Newchar:
	mov ah,1
	int 21h    ;读入一个字符
	sub al,30h 
	jl  decibin_Exit
	cmp al,9d
	jg   decibin_Exit;如非十进制数,退出。
	cbw        ;扩展AL中的数到AX中
xchg ax,bx   ;
	 mov cx,10d
	 mul cx
	 xchg ax,bx
	 add bx,ax
     jmp decibin_Newchar
decibin_Exit: 
     ret
Decibin  endp
;-----------------------------------------
crlf	proc	;过程开始
	push ax	;保护寄存器AX和DX
	push dx
	mov dl,0dh	;显示回车
	mov ah,2
	int 21h
	mov dl,0ah	;显示换行
	mov ah,2
	int 21h
	pop dx	;恢复寄存器DX和AX
	pop ax
	ret	;子程序返回
crlf	endp	;过程结束
;------------------------------------------
	code ends
end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -