鱼C论坛

 找回密码
 立即注册
查看: 5241|回复: 8

[已解决]请问汇编语言怎么输出寄存器中的数

[复制链接]
回帖奖励 10 鱼币 回复本帖可获得 1 鱼币奖励! 每人限 1 次(中奖概率 20%)
发表于 2017-4-7 11:37:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
如题,谢谢
最佳答案
2017-4-7 15:57:15
  1. assume cs:code, ss:stack

  2. stack segment
  3.         db 100 dup(?)
  4. stack ends

  5. code segment


  6. ;显示十六进制数到屏幕
  7. ;void show_hex(word data);
  8. show_hex:
  9.         push bp
  10.         mov bp, sp
  11.         ;sub sp, 10h
  12.        
  13.         push ax
  14.         push cx
  15.         push bx
  16.         push dx
  17.        
  18.         mov ax, 0b800h
  19.         mov es, ax
  20.         xor si, si ;es:si -> 当前显示位置
  21.        
  22.         mov ax, [bp + 4] ;mov ax, data
  23.        
  24.        
  25.         mov cx, 4
  26. show_hex_s:
  27.         mov bx, ax
  28.         and bx, 0f000h
  29.        
  30.         push cx
  31.         mov cl, 12
  32.         shr bx, cl
  33.         pop cx
  34.        
  35.         cmp bx, 0ah
  36.         jl show_hex_less_a
  37.        
  38.         sub bx, 0ah
  39.         add bx, 'A'
  40.         jmp show_hex_less_n
  41.        
  42. show_hex_less_a:
  43.         add bx, '0'

  44. show_hex_less_n:
  45.         push ax
  46.        
  47.         ;输出bl中的字符
  48.         mov ah, 0eh
  49.         mov al, bl
  50.         int 10h
  51.        
  52.         pop ax
  53.        
  54.        
  55.         push cx
  56.         mov cl, 4
  57.         shl ax, cl
  58.         pop cx
  59.         loop show_hex_s
  60.        
  61.        
  62.         pop dx
  63.         pop bx
  64.         pop cx
  65.         pop ax
  66.        
  67.         mov sp, bp
  68.         pop bp
  69.         ret

  70. start:
  71.         mov ax, stack
  72.         mov ss, ax
  73.         mov sp, 100
  74.        
  75.         mov cx, 0ffffh
  76. s:
  77.         ;显示cx中的值
  78.         push cx
  79.         call show_hex
  80.         add sp, 2
  81.        
  82.         ;输出空格
  83.         push ax
  84.         mov ah, 0eh
  85.         mov al, ' '
  86.         int 10h
  87.        
  88.         loop s
  89.        
  90.         mov ax,4c00h
  91.         int 21h
  92. code ends

  93. end start
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-4-7 12:19:45 | 显示全部楼层
输出到屏幕?还是。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-7 15:57:15 | 显示全部楼层    本楼为最佳答案   
  1. assume cs:code, ss:stack

  2. stack segment
  3.         db 100 dup(?)
  4. stack ends

  5. code segment


  6. ;显示十六进制数到屏幕
  7. ;void show_hex(word data);
  8. show_hex:
  9.         push bp
  10.         mov bp, sp
  11.         ;sub sp, 10h
  12.        
  13.         push ax
  14.         push cx
  15.         push bx
  16.         push dx
  17.        
  18.         mov ax, 0b800h
  19.         mov es, ax
  20.         xor si, si ;es:si -> 当前显示位置
  21.        
  22.         mov ax, [bp + 4] ;mov ax, data
  23.        
  24.        
  25.         mov cx, 4
  26. show_hex_s:
  27.         mov bx, ax
  28.         and bx, 0f000h
  29.        
  30.         push cx
  31.         mov cl, 12
  32.         shr bx, cl
  33.         pop cx
  34.        
  35.         cmp bx, 0ah
  36.         jl show_hex_less_a
  37.        
  38.         sub bx, 0ah
  39.         add bx, 'A'
  40.         jmp show_hex_less_n
  41.        
  42. show_hex_less_a:
  43.         add bx, '0'

  44. show_hex_less_n:
  45.         push ax
  46.        
  47.         ;输出bl中的字符
  48.         mov ah, 0eh
  49.         mov al, bl
  50.         int 10h
  51.        
  52.         pop ax
  53.        
  54.        
  55.         push cx
  56.         mov cl, 4
  57.         shl ax, cl
  58.         pop cx
  59.         loop show_hex_s
  60.        
  61.        
  62.         pop dx
  63.         pop bx
  64.         pop cx
  65.         pop ax
  66.        
  67.         mov sp, bp
  68.         pop bp
  69.         ret

  70. start:
  71.         mov ax, stack
  72.         mov ss, ax
  73.         mov sp, 100
  74.        
  75.         mov cx, 0ffffh
  76. s:
  77.         ;显示cx中的值
  78.         push cx
  79.         call show_hex
  80.         add sp, 2
  81.        
  82.         ;输出空格
  83.         push ax
  84.         mov ah, 0eh
  85.         mov al, ' '
  86.         int 10h
  87.        
  88.         loop s
  89.        
  90.         mov ax,4c00h
  91.         int 21h
  92. code ends

  93. end start
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-9-16 12:12:58 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-9-16 12:14:48 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-9-16 12:15:31 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-9-16 17:26:00 | 显示全部楼层
...
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-5-2 15:40:59 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-5-5 15:30:25 | 显示全部楼层
这么久了鱼币还没有领完
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-24 06:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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