zoukankan      html  css  js  c++  java
  • 汇编语言-王爽-课程设计1

    子程序dtod将dx、ax表示的32位数字转化为si指向的以0结尾的字符串,dtoc、divdw、show_str按照书中要求,前面的实验8用于生成table段的代码改成子程序build。

      1 data segment
      2         db '1975','1976','1977','1978','1979','1980','1981','1982','1983'
      3 
      4         db '1984','1985','1986','1987','1988','1989','1990','1991','1992'
      5 
      6         db '1993','1994','1995'
      7 
      8         ;以上是表示21年的21个字符串
      9 
     10 
     11         dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
     12 
     13         dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
     14 
     15         ;以上是表示21年公司总收的21个dword型数据
     16 
     17 
     18         dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
     19 
     20         dw 11542,14430,15257,17800
     21 
     22         ;以上是表示21年公司雇员人数的21个word型数据
     23 
     24 ;临时内存空间
     25 temp:    db 11 dup(0)
     26 data ends
     27 
     28 table segment
     29         db 21 dup('year summ ne ?? ')
     30 table ends
     31 
     32 stack segment
     33 dw 0,84,168
     34 dw 27 dup(0)
     35 stack ends
     36 
     37 code segment
     38     assume cs:code,ds:data,ss:stack
     39 main:
     40     mov ax,data
     41     mov ds,ax
     42     mov ax,stack
     43     mov ss,ax
     44     mov sp,60
     45 
     46     call build
     47     
     48     mov bx,0e0h
     49     mov cx,21
     50     mov dh,0
     51     
     52     mainl1:
     53         push cx
     54         mov cx,0002h
     55         
     56         mov dl,0
     57         mov byte ptr [bx].4,0
     58         mov si,bx
     59         call show_str
     60         
     61         push dx
     62         mov ax,[bx].5
     63         mov dx,[bx].7
     64         mov si,offset temp
     65         call dtod
     66         pop dx
     67         mov dl,10
     68         call show_str
     69         
     70         mov ax,[bx].10
     71         call dtoc
     72         mov dl,20
     73         call show_str
     74         
     75         mov ax,[bx].13
     76         call dtoc
     77         mov dl,30
     78         call show_str
     79         
     80         inc dh
     81         add bx,16
     82         pop cx
     83     loop mainl1
     84     
     85     
     86 
     87     mov ah,4ch
     88     int 21h
     89 
     90 build:
     91 push ax
     92 push bx
     93 push cx
     94 push si
     95 
     96 mov bx,0e0h
     97 mov cx,21
     98 
     99 buildl1:;构造21行
    100     ;年份
    101     mov si,ss:[0]
    102     mov ax,[si]
    103     mov [bx].0,ax
    104     mov ax,2[si]
    105     mov [bx].2,ax
    106     
    107     ;收入
    108     mov si,ss:[2]
    109     mov ax,[si]
    110     mov [bx].5,ax
    111     mov ax,2[si]
    112     mov [bx].7,ax
    113     
    114     ;雇员
    115     mov si,ss:[4]
    116     mov ax,[si]
    117     mov [bx].0ah,ax
    118     
    119     ;人均收入
    120     mov ax,[bx].5
    121     mov dx,[bx].7
    122     div word ptr [bx].0ah
    123     mov [bx].0dh,ax
    124     
    125     add word ptr ss:[0],4
    126     add word ptr ss:[2],4
    127     add word ptr ss:[4],2
    128     add bx,16
    129 loop buildl1
    130 
    131 pop si
    132 pop cx
    133 pop bx
    134 pop ax
    135 ret
    136 
    137     
    138 ;arg si dh dl cl
    139 ;bx es ax cx
    140 show_str:
    141 push ax
    142 push bx
    143 push cx
    144 push dx
    145 push si
    146 push es
    147 
    148 ;算出写入地址bx
    149 mov ax,0b800h
    150 mov es,ax
    151 mov al,0a0h
    152 mul dh
    153 
    154 mov bx,ax
    155 mov dh,0
    156 add dx,dx
    157 add bx,dx
    158 
    159 ;al存样式
    160 mov al,cl
    161 mov ch,0
    162 show_strl1:
    163     mov cl,[si]
    164     jcxz show_stro1
    165     mov es:[bx],cl
    166     mov es:1[bx],al
    167     inc si
    168     add bx,2
    169 jmp show_strl1
    170 
    171 show_stro1:
    172 pop es
    173 pop si
    174 pop dx
    175 pop cx
    176 pop bx
    177 pop ax
    178 ret
    179 
    180 
    181 ;ax bx cx dx
    182 divdw:
    183 push bx
    184 
    185 ;保存低位
    186 push ax
    187 mov ax,dx
    188 mov dx,0
    189 div cx
    190 ;保存高位商
    191 mov bx,ax
    192 pop ax
    193 div cx
    194 mov cx,dx
    195 mov dx,bx
    196 
    197 pop bx
    198 ret
    199 
    200 
    201 ;arg si ax
    202 ;use dx,bx,cx
    203 dtoc:
    204 push ax
    205 push bx
    206 push cx
    207 push dx
    208 push si
    209 
    210 mov byte ptr [si].5,0
    211 ;最大5位数
    212 mov bx,4
    213 
    214 dtocl1:
    215     ;高位置0
    216     mov dx,0
    217     mov cx,10
    218     div cx
    219     add dl,30h
    220     mov [si][bx],dl
    221     mov cx,ax
    222     jcxz dtoco1
    223     dec bx
    224 jmp dtocl1
    225 
    226 dtoco1:
    227 ;判断是否需要移动
    228 mov cx,bx
    229 jcxz dtocend
    230 
    231 ;向前移动
    232 mov ch,0
    233 dtocl2:
    234     mov cl,[si][bx]
    235     mov [si].0,cl
    236     jcxz dtocend
    237     inc si
    238 jmp dtocl2
    239 
    240 dtocend:
    241 pop si
    242 pop dx
    243 pop cx
    244 pop bx
    245 pop ax
    246 ret
    247 
    248 
    249 ;arg si ax dx
    250 ;use bx,cx
    251 dtod:
    252 push ax
    253 push bx
    254 push cx
    255 push dx
    256 push si
    257 
    258 mov byte ptr [si].10,0
    259 ;最大10位数,从[9]开始写入
    260 mov bx,9
    261 
    262 dtodl1:
    263     mov cx,10
    264     call divdw
    265     add cl,30h
    266     mov [si][bx],cl
    267 
    268     ;当dx、ax都为0时退出循环
    269     mov cx,ax
    270     or cx,dx
    271     jcxz dtodo1
    272     dec bx
    273 jmp dtodl1
    274 
    275 dtodo1:
    276 ;判断是否需要移动
    277 mov cx,bx
    278 jcxz dtodend
    279 
    280 ;向前移动
    281 mov ch,0
    282 dtodl2:
    283     mov cl,[si][bx]
    284     mov [si].0,cl
    285     jcxz dtodend
    286     inc si
    287 jmp dtodl2
    288 
    289 dtodend:
    290 pop si
    291 pop dx
    292 pop cx
    293 pop bx
    294 pop ax
    295 ret
    296 
    297 
    298 code ends
    299 end main
    10.asm
  • 相关阅读:
    脚本,网络配置,指令
    拦截TextBox 双击消息
    VB指针操作和消息钩子
    文件和文件夹操作
    常见反编译产生错误 k__BackingField 解决办法
    关机/重启/注销
    通用命名前缀
    语言区域代码
    常用数据库链接字符串
    用VB实现COM+组件配置
  • 原文地址:https://www.cnblogs.com/zackcoder/p/3373947.html
Copyright © 2011-2022 走看看