我试图在汇编中制作加密/解密程序。它工作正常,但我必须手动输入ror和rol的位数。我想知道我是否可以做一些像ror eax,n,其中n是我的变量,介于1和7之间,从键盘读取。我怎样才能做到这一点 ?谢谢。这是我的代码。
.data
tfile1 db "text.txt", 0
read db "rb", 0
write db "wb",0
format db "%c", 0
msg1 DB "n=",0
n DD 0
formatd DB "%d",0
buffer db 0
.code
start:
push offset msg1 ; put msg1 on stack
call printf ; print msg1
add esp,4 ; clear stack
push offset n ; put n on stack
push offset formatd ; put n format on stack
call scanf ; write n value
add esp,8 ; clear stack
mov ebx,n ; copy n in ebx
push ebx ; put n on stack
push offset formatd ; put n format on stack
add esp,8 ; clear stack
push offset read ;put read binary operation on stack
push offset tfile1 ;put text.txt on stack
call fopen ;open text.txt
add ESP, 8 ;clear stack
mov esi, eax ;save pointer to the stack
push esi ;stream
push 1 ;count
push 1 ;size
push offset buffer
read_loop:
call fread
test eax,eax ;check if eax=0
jz close_tfile
xor eax, eax ;clear eax
mov al, buffer ; copy buffer in al
not eax ;1's complement
add eax,1 ; 2's complement
ror eax,3 ; ror eax with 3 ! Here's my problem I wana imput the bytes value
rol eax,3 ; rol eax with 3 ! Here's my problem I wana imput the bytes value
not eax ; 2's complement
add eax,1 ; 1's complement
push eax ; put eax on stack
push offset format ; put format on stack
call printf ; print from text.txt
add esp, 8 ;clear stack
jmp read_loop
close_tfile:
add esp, 16 ; clear stack from fread
push esi ;stream
call fclose
add esp,4
push 0
call exit
结束开始