汇编语言实验课:第六次记录


前言

输入十个数字再输出

一、程序

DATAS SEGMENT
    a0 dw 12 dup(?)  
DATAS ENDS

STACKS SEGMENT
    ;此处输入堆栈段代码
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
    
    ;初始化
    mov si,offset a0
    mov bl,0
    
    ;比较10和bl相等跳到L2,否则调用input函数,把输入的数存到a0中
L3:    
    cmp bl,10
    je L2
    call input
    mov [si],cx
    add bl,1
    add si,2
    jmp L3
    
    ;初始化
L2:
	mov si,offset a0
	mov bl,0
	
	;比较bl和10相等跳到L1结束,否则就调用output函数输出数据
L0:
	cmp bl,10
	je L1
	mov ax,[si]
	call output
	add bl,1
	mov dl,' '
	mov ah,2
	int 21h
	add si,2
	jmp L0
	
L1:
    MOV AH,4CH
    INT 21H
    
   
input proc   ;cx为出口参数

    push ax
    push bx
    push dx
    
    ;初始化
    mov bl,10
    mov cx,0
    
    ;输入数字
input2:
	mov ah,1
	int 21h
	cmp al,'0'
	jb input1
	cmp al,'9'
	ja input1
	
	sub al,48
	mov dl,al
	mov al,cl
	mul bl
	add al,dl
	mov cx,ax
	jmp input2

input1:
    pop dx
    pop bx
    pop ax
    
    ret
input endp


    
output proc    ;ax为入口参数

    push ax
    push bx
    push cx
    push dx
    
    ;初始化
    mov cl,10
    mov bl,0
    
    ;输出数字
output2:
    cmp al,0
    je output1
    div cl
    push ax
    add bl,1
    mov ah,0
    jmp output2
    
output1:
    cmp bl,0
    je output3
    pop cx
    sub bl,1
    mov dl,ch
    add dl,48
    mov ah,2
    int 21h
    jmp output1
output3:
    

    pop dx
    pop cx
    pop bx
    pop ax
    
    ret
output endp
    
    
CODES ENDS
    END START

总结

成功的交上了作业

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值