飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 2809|回复: 0

[C/C++] 《汇编语言》实验十 即17课作业代码

[复制链接]

该用户从未签到

发表于 2010-12-28 20:39:38 | 显示全部楼层 |阅读模式
本帖最后由 sosonemo 于 2010-12-28 20:42 编辑

没看17课之前先写的代码,没有使用cmp和条件跳转指令,按书上的思想写出来的。
  1. assume cs:code

  2. data segment
  3.    db 10 dup(0)
  4. data ends

  5. stack segment
  6.    db 30 dup(0)
  7. stack ends

  8. code segment
  9.   start:     mov ax,stack
  10.              mov ss,ax
  11.              mov sp,30
  12.              mov ax,12666   ;(ax)=word型数据
  13.              mov bx,data
  14.              mov ds,bx
  15.              mov si,0       ;ds:si指向字符串
  16.           call dtoc
  17.                          
  18.           mov si,0
  19.           mov dh,12      ;行(0开始)
  20.           mov dl,12      ;列(0开始)
  21.           mov cl,00100100b ;属性
  22.           call show_str
  23.                          
  24.           mov ax,4c00h
  25.           int 21h
  26.   dtoc:
  27.                          push cx
  28.                          push dx
  29.                          push di
  30.                          mov di,0
  31.                 s1:         mov cx,10
  32.                             mov dx,0
  33.                          div cx       ;ax=1266  dx=6
  34.              add dx,30h                         
  35.                          push dx
  36.                          inc di
  37.                          mov cx,ax                         
  38.                          jcxz ok
  39.                          jmp s1
  40.                 ok:         
  41.                      mov cx,di
  42.                  s2: pop word ptr [si]
  43.                      inc si
  44.                      loop s2
  45.                          
  46.                      pop di
  47.                          pop dx
  48.                      pop cx
  49.                          ret
  50.   show_str:
  51.                           push ax
  52.                        push dx
  53.                        push cx
  54.                      push bx
  55.                      push es
  56.                  
  57.                      mov ax,0b800h
  58.                      mov es,ax
  59.                   
  60.                      mov al,160
  61.                      mul dh
  62.                      mov bx,ax     ;计算行
  63.                         mov al,2
  64.                      mul dl
  65.                      add bx,ax     ;行+列,即首地址
  66.                   
  67.                      mov dh,cl
  68.                      mov ch,0
  69.         s:             mov cl,[si]
  70.                      jcxz ok1
  71.                      mov es:[bx],cl
  72.                      mov es:[bx+1],dh
  73.                      inc si
  74.                      add bx,2
  75.                      jmp s
  76.     ok1:   
  77.                         pop es
  78.                      pop bx
  79.                      pop cx
  80.                      pop dx
  81.                      pop ax
  82.                      ret
  83. code ends
  84. end start
  85.                          
  86.                          
复制代码
PYG19周年生日快乐!
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表