Reputation: 174
I am new to assembly language programming.
Can anyone figure out where I am going wrong?
The error while assembling is
Rotate count out of Range error
Error is at line: rol bl, 04
This is my code:
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
Upvotes: 0
Views: 2244
Reputation: 21552
Real mode has a lot more limitations than protected mode about which registers do what and which instructions are valid. If you're used to programming in protected mode and long mode you should probably become familiar with these restrictions.
Another really commonly encountered restriction is that only the registers BX
and BP
are valid as base address offsets; the instruction 00 00
(add byte ptr [eax], al
) in protected mode becomes add [bx+si], al
in real mode, for example.
If the amount you are rotating by is not exactly 1, you need to put the count in CL
and use that as the second operand for the ro[l|r]
instruction - immediate values other than 1 are not valid.
Upvotes: 0
Reputation: 16351
The ROR
and ROL
instructions in the 8086 instruction set take either an immediate value of 1 or a count stored in CL
. To rotate 4 bits, you would need to do this:
MOV CL, 4
ROR BL, CL
Upvotes: 4