微机原理阶梯电价.doc
文本预览下载声明
阶梯电价源代码
?;注意,附加实验和上课讲的过程调用例程不完全一致,附加实验基本说明如下:
?;1、编写子程序,读入20名用户的用电量,并且存在某段单元中。
?;2、编写子程序,获得上一步的最大值。
?;3、编写子程序,根据阶梯电价函数,求取最大用电量用户应付价格。
?;定义堆栈段STACK SEGMENT STACK STACKSTA DB 200 DUP(?)TOP EQU LENGTH STASTACK ENDS
;定义数据段data segmenttolnum equ 20price dd 0max dw 0users dw tolnum dup(?)input db input the number, 0ah, 0dh, $keynum dw ?inputnums dw 0perprice1 dw 49perprice2 dw 54perprice3 dw 79dianliang dw 0step1 equ 200step2 equ 340data ends
;代码段code segmentassume cs:code, ds:data, ss:STACK;dec2bin过程定义 从键盘读数,转成二进制,存入users;入口参数:无;出口参数:users (keynum和inputnums是局部变量);用到的子程序:1号功能调用;用到的寄存器:ax, bx, cx, dx, sidec2bin 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 21hnextuser:??? mov ax, 0??? mov inputnums, ax??? mov keynum, axnextkey:??? 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 nextkeydetectspace:??? mov ax, inputnums??? mov users[si], ax??? inc si??? inc si??? loop nextuserexit:??? pop si??? pop dx??? pop cx??? pop bx??? pop ax??? retdec2bin endp
;GetMax 从users中寻求最大值,存入Max;入口参数:users;出口参数:max;用到的子程序;用到的寄存器:ax, bx, cx, siGetMax proc near??? push ax??? push bx??? push cx??? push si??????? mov si, 0??? mov cx, tolnum??? mov bx, max??? mov ax, users[si]????goon:??? mov ax, users[si]??? cmp ax, bx??? jb smaller??? mov bx, axsmaller:??? inc si??? inc si??? loop goon??? mov max, bx??????? pop si??? pop cx??? pop bx??? pop ax??? retGetMax endp
;GetPrice将dianliang映射为price;入口参数:dianliang, perprice1, perprice2, perprice3;出口参数:price;用到的子程序;用到的寄存器:ax, dxGetPrice proc near??? push ax??? push dx??? cmp dianliang, step1??? ja largerthan200??? mov ax, perprice1??? jmp callargerthan200:??? cmp
显示全部