【问题标题】:And function with SHL FUNCTION并与 SHL FUNCTION 一起发挥作用
【发布时间】:2015-02-21 03:48:48
【问题描述】:

,,,,,01011011b 和 11000111b ;;;我试图将结果显示为二进制数字的 ascii 字符串。 我正在使用 shl 指令来隔离每个位并跳转进位。我能打印的都是乱码。有人可以帮忙吗?

    .stack 100h
    .model small
    .386

    .data

    str1  db  20 dup(?)
    lstring EQU 9

    .code

main: 
    mov ax, @data                ; initialize DS
    mov ds, ax
    mov cx, lstring
L1: 
    mov al,01011011b                     
    and al,11000111b             
    shl al, 1
    mov str1, al
    mov ax, 8
    loop L1

    mov ax, 4000h                   ;   dos service to display...
    mov bx, 1                   ;   to screen
    mov cx, lstring             ;   number of bytes
    mov dx, OFFSET str1         ;   where to get data
    int 21h

    MOV AH, 4CH                 ; return control to DOS
    INT 21H

end main    

【问题讨论】:

  • “我正在使用 shl 指令来隔离每个位并跳转进位。” 您发布的代码中没有进位跳转。为什么循环的每次迭代都进行AND 计算,而不是一次? mov ax, 8 应该做什么?
  • 是的,整个循环基本不变,9次迭代后的结果和第一次没有区别。

标签: assembly x86


【解决方案1】:

您应该使用寄存器动态地处理您的输出字符串 str1。 DI 是最好的选择:

  mov di,str1 ; Address of the first byte of output string.
  mov cx,8 ; Number of bits to print.
L1:
  shl al,1 ; Put the most significant bit of AL to CF.
  mov dl,'0' ; Output ASCII character.
  adc dl,0  ; Change it from '0' to '1' when CF was set.
  mov [di],dl ; Store the ASCII character to output string.
  inc di ; Let di point to the next character.
  loop L1 ; Repeat with remaining bits.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多