旋转计数超出范围错误

时间:2017-02-06 16:23:30

标签: assembly dos x86-16 tasm

我是汇编语言编程的新手 任何人都可以弄清楚我哪里出错了吗? 组装时的错误是

  

旋转计数超出范围错误
  错误在行:rol bl,04

这是我的代码:

disp macro var
    lea dx, var
    mov ah, 09H
    int 21H
endm

ending macro
    mov ah, 4cH
    int 21H
endm

.model small
.stack 100H
.data
        msg1 db 10, 13, "_____STRING OPERATION_____$"
        msg2 db 10, 13, "1.Length", 10, 13, "2.Reverse $"
        msg3 db 10, 13, "3.Exit", 10, 13, "--->$"
        error db 10, 13, "Enter a valid choice ",10, 13, "$"
        msg4 db 10, 13, "Enter the string: $"
        msg5 db 10, 13, "Length of the string: $"
        msg6 db 10, 13, "Reversed String: $"
        choice db ?
        str1 db 20, ?, 20 dup(0)
.code
        mov ax, @data
        mov ds, ax

menu:   disp msg1
        disp msg2
        disp msg3

        mov ah, 01H
        int 21H
        mov choice, al

        cmp choice, 31H
        je str_len
        cmp choice, 32H
        je Reverse
        cmp choice, 33H
        je Exit
        disp error
        jmp menu

str_len:disp msg4
        mov ah, 0aH
        lea dx, str1
        int 21H

        disp msg5

        lea si, str1[1]
        mov bl, [si]
        mov cl, 02
back:   rol bl, 04
        mov dl, bl

        mov ah, 02H
        int 21H
        loop back

        ending

Reverse:

Exit:   ending

end

2 个答案:

答案 0 :(得分:4)

8086指令集中的RORROL指令采用立即值1或存储在CL中的计数。要旋转4位,您需要执行以下操作:

 MOV  CL, 4
 ROR  BL, CL

答案 1 :(得分:0)

实模式比保护模式有更多限制,关于哪些寄存器执行哪些操作以及哪些指令有效。如果您习惯于在保护模式和长模式下编程,则应该熟悉这些限制。

另一个经常遇到的限制是只有寄存器SELECT City FROM ( SELECT City, Animal FROM ( SELECT City, Animal1 AS Animal FROM mytable UNION ALL SELECT City, Animal2 AS Animal FROM mytable UNION ALL SELECT City, Animal3 AS Animal FROM mytable UNION ALL SELECT City, Animal4 AS Animal FROM mytable ) AS t GROUP BY City, Animal HAVING COUNT(*) >= 2) AS x GROUP BY City HAVING COUNT(*) >= 2 BX作为基地址偏移有效;例如,受保护模式下的指令BP00 00)在实模式下变为add byte ptr [eax], al

如果您旋转的数量不是1,则需要将计数放在add [bx+si], al中并将其用作CL指令的第二个操作数 - 除1之外的立即数不是有效的。