首页 > 解决方案 > x64 汇编语言中的轮换

问题描述

以下是我的指示。有点挣扎,不知道该怎么办。。

您的程序应该首先调用 ReadString (IO.cpp) 以获取一些合理长度的消息。接下来,调用 PROC 执行加密,将结果保存在新的内存位置。调用 DisplayMemory 在屏幕上显示加密值。还显示(但不需要加密)ReadString 返回的标记值。调用 DisplayNewline。然后,调用一个 PROC 来解密您的加密消息(通过将每个字节中的所有位向左旋转 3 个位置)。最后,调用 DisplayString 以显示您的解密消息。它应该与用户输入的字符串匹配。

这是一些示例输出(第一行由用户输入):

now is the time for all good men
73 7b bb 01 4b 9b 01 a3 43 2b 01 a3 4b 6b 2b 01 33 7b 93 01 0b 63 63 01 3b 7b 7b 23 01 6b 2b 73 00
now is the time for all good men

到目前为止,这是我的代码:

extrn ExitProcess:          PROTO
extrn DisplayString:        PROTO
extrn ReadString:           PROTO

.data?
string1         byte        40 dup(?)
string2         byte        ?

.code
Rotate          PROC

                mov  rax, 0                     ;counter = 0
Loop1:
                cmp  rax, rdx                   ;counter is less than string1 length
                jge  Done                       ;exit loop once string is processed
                mov  al, byte ptr[rcx + rax]
                ror  al, 3
                mov  byte ptr[rcx + rax], al

                inc rax
                jmp Loop1

Done:
                mov  byte ptr[r8 + rax], 0
                mov  rax, r8
                ret                                 ;return
Rotate          ENDP

main            PROC
                push rbp                            ;save non-volatile  
                mov  rbp, rsp                       ;make frame pointer for stack
                sub  rsp, 32                        ;reserve shadow space

                lea  rcx, string1
                call ReadString
                call Rotate
                sub  eax, 1
                mov  edx, eax
                lea  rcx, string2
                mov  rcx, rax
                call DisplayString

                add  rsp, 32                        ;restore shadows space
                pop  rbp                            ;save non-volatile stack
                xor  rcx, rcx                       ;return code
                call ExitProcess                    ;windows exit
main            ENDP
END

标签: assemblyx86-64

解决方案


推荐阅读