汇编语言(assembly language)实现方程的计算

~~

##汇编语言(assembly language)实现方程的计算
鬼刀一开,看不见,走位

*题目描述:y=4x-5,输入一个十进制一位的x,输出y

其实是有三种做法的。。

打表,别问我怎么会如此zz
2.

data	segment
m1			db	0dh,0ah,'y=4*x-5;x=','$'
m2			db	0dh,0ah,'y=','$'
results     db 	?,?,"$"        
code	segment
assume	cs:code,ds:data
start:		
			mov	ax,data			
			mov	ds,ax				
input:	    
			lea dx,m1
			mov ah,9
			int 21h
			mov ah,1
	        int 21h						
	        cmp al,1bh
	        je 	exit
	        and al,00001111b			;根据ascii,减去30h			
	        mov bl,4
	        mul bl  
	        sub ax,5
	        mov cx,ax
	        lea dx,m2
			mov ah,9
			int 21h
			mov ax,cx
	        cmp ax,8000h
	        ja flag
temp:	    
			mov bl,10
	        div bl						;al商,ah余ax商,dx余
	        or  al,00110000b
	        or  ah,00110000b
	        cmp al,'0'
	        je s2
	        jne s1
flag:		
			mov ah,2
			mov dl,'-'
			int 21h
			mov ax,cx
			neg ax
			jmp temp
s1:	        
			mov results,al
			mov results+1,ah
			jmp output2 
s2:			
			mov results,ah
			mov results+1,'$'
output2:	
			mov ah,9
			lea dx,results
			int 21h
			jmp input
exit:		
			mov	ah,4ch						
			int	21h
code	ends
end	start

3

data	segment
m1			db	0dh,0ah,'y=4*x-5;x=','$'
m2			db	0dh,0ah,'y=','$'加粗样式
r0			db	0dh,0ah,'y=-5','$'
r1			db	0dh,0ah,'y=-1','$'
results     db 	?,?,"$"        
code	segment
assume	cs:code,ds:data
start:		
			mov	ax,data			
			mov	ds,ax				
input:	    
			lea dx,m1
			mov ah,9
			int 21h
			mov ah,1
	        int 21h						
	        cmp al,1bh
	        je 	exit
	        cmp al,'1'
	        je  output1
	        cmp al,'0'
	        je 	output0
	        and al,00001111b			;根据ascii,减去30h			
	        mov bl,4
	        mul bl   
	        sub ax,5        
	        mov bl,10
	        div bl						;al商,ah余ax商,dx余
	        or  al,00110000b
	        or  ah,00110000b
	        cmp al,'0'
	        je s2
s1:	        
			mov results,al
			mov results+1,ah
			jmp output2 
s2:			
			mov results,ah
			mov results+1,'$'
			jmp output2
output0:
			lea dx,r0
			mov ah,9
			int 21h
			jmp input			
output1:
			lea dx,r1
			mov ah,9
			int 21h
			jmp input
output2:	
			mov ah,9
			lea dx,m2
			int 21h
			mov ah,9
			lea dx,results
			int 21h
			jmp input
exit:		
			mov	ah,4ch						
			int	21h
code	ends
end	start

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值