和SHL FUNCTION一起使用

时间:2015-02-21 03:48:49

标签: assembly x86

,,,,, 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    

1 个答案:

答案 0 :(得分:0)

您应该使用寄存器动态地处理输出字符串 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.