文档详情

微机原理阶梯电价.doc

发布:2017-06-20约2.52千字共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 ;GetMax 从users中寻求最大值,存入Max ;入口参数:users ;出口参数:max ;用到的子程序 ;用到的寄存器:ax, bx, cx, si GetMax 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, ax smaller: ??? inc si ??? inc si ??? loop goon ??? mov max, bx ???? ??? pop si ??? pop cx ??? pop bx ??? pop ax ??? ret GetMax endp ;GetPrice将dianliang映射为price ;入口参数:dianliang, perprice1, perprice2, perprice3 ;出口参数:price ;用到的子程序 ;用到的寄存器:ax, dx GetPrice proc near ??? push ax ??? push dx ??? cmp dianliang, step1 ??? ja largerthan200 ??? mov ax, perprice1 ??? jmp cal largerthan200: ??? cmp
显示全部
相似文档