[Homework] [x86 Assembly] ROR/ROL using non-constants via /r/learnprogramming


[Homework] [x86 Assembly] ROR/ROL using non-constants

I'm attempting a particular problem in a workbook I'm using, which involves using an array of byte called Key to encrypt one or more string messages. I must loop through both Key and the message I wish to encrypt, and if the number in Key is positive I use ROR [that number], and ROL if it is negative. For instance, if the next character in the message is 'A', and the number is '+2', I use ROR 2 on the byte of 'A'. If the number is '-2', I use 'ROL 2'.

My code is as follows:

.386 .model flat,stdcall .stack 4096 ExitProcess proto,dwExitCode:dword INCLUDE irvine32.inc .data key SBYTE -2, +4, +1, 0, -3, 5, 2, -4, -4, 6 message1 BYTE "this is a message FROM THE FUTUUUUUUUUUURE" message2 BYTE "oh yeah well THIS IS A MESSAGE FROM THE PAAAAAST" move BYTE ? .code ;Encrypt: Takes a message and encrypts it according to a key of byte values, positive or neagtive. ;Receives esi as offset of message, and edi as offset of key. encrypt PROC uses edx mov dl, 0 L1: mov al, [edi] cmp al, 0 jl isless mov move, al ror BYTE PTR[esi], move ;cmp al to 0. If less than 0, jump to isless and rol. Otherwise, ror. jmp increment isless: neg al rol BYTE PTR[esi], al inc esi inc edi inc dl LOOP L1 ret encrypt endp main proc mov esi, OFFSET message1 mov edi, OFFSET key call encrypt invoke ExitProcess,0 main endp end main However, Visual Studio throws an error when I attempt to compile. On Lines 22 and 26 (the ror and rol commands, respectively), I get the following: 

error A2070: invalid instruction operands

This led to me attempting to move the contents of the al register to a variable named "move", and then using that as my second operand for ror. It didn't help for that command, and so won't help for rol either.

I experimented a little and found that if I passed the argument as an imm8 (that is, if I said ror BYTE PTR[esi], 2), that causes no error. However, if I wanted to implement that, I would need to create a massive string of cmp commands, and it would need to be rewritten fully every time I changed Key. With that in mind, what solution(s) are available to work around this error?

Submitted July 12, 2017 at 03:36PM by Kesseleth
via reddit http://ift.tt/2tJMI0U

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s