下载此文档

微机原理阶梯电价.doc


文档分类:高等教育 | 页数:约4页 举报非法文档有奖
1/4
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/4 下载此文档
文档列表 文档介绍
阶梯电价源代码
 ;注意,附加实验和上课讲的过程调用例程不完全一致,附加实验基本说明如下:
 ;1、编写子程序,读入20名用户的用电量,并且存在某段单元中。
 ;2、编写子程序,获得上一步的最大值。
 ;3、编写子程序,根据阶梯电价函数,求取最大用电量用户应付价格。
 ;定义堆栈段
STACK SEGMENT STACK 'STACK'
STA DB 200 DUP(?)
TOP EQU LENGTH STA
STACK ENDS
;定义数据段
data segment
tolnum equ 20
price dd 0
max dw 0
users dw tolnum dup(?)
input db 'input the number', 0ah, 0dh, '$'
keynum dw ?
inputnums dw 0
perprice1 dw 49
perprice2 dw 54
perprice3 dw 79
dianliang dw 0
step1 equ 200
step2 equ 340
data ends
;代码段
code segment
assume cs:code, ds:data, ss:STACK
;dec2bin过程定义从键盘读数,转成二进制,存入users
;入口参数:无
;出口参数:users (keynum和inputnums是局部变量)
;用到的子程序:1号功能调用
;用到的寄存器:ax, bx, cx, dx, si
dec2bin proc near
    push ax
    push bx
    push cx
    push dx
    push si
    
    mov si, 0
    mov bx, 10
    mov cx, tolnum
    mov dx, offset input
    mov ah, 09h
    int 21h
nextuser:
    mov ax, 0
    mov inputnums, ax
    mov keynum, ax
nextkey:
    mov ah, 1
    int 21h
    cmp al, 20h
    jz detectspace
    sub al, 30h
    cmp al, 0
    jb exit
    cmp al, 9
    ja exit
    cbw
    mov keynum, ax
    mov ax, inputnums
    mul bx
    add ax, keynum
    mov inputnums, ax
    jmp nextkey
detectspace:
    mov ax, inputnums
    mov users[si], ax
    inc si
    inc si
    loop nextuser
exit:
    pop si
    pop dx
    pop cx
    pop bx
    pop ax
    ret
dec2bin endp

微机原理阶梯电价 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数4
  • 收藏数0 收藏
  • 顶次数0
  • 上传人mh900965
  • 文件大小28 KB
  • 时间2017-06-22