阶梯电价源代码
;注意,附加实验和上课讲的过程调用例程不完全一致,附加实验基本说明如下:
;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
微机原理阶梯电价 来自淘豆网m.daumloan.com转载请标明出处.