Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ARM汇编语言:caesar cypher_Arm_Character - Fatal编程技术网

ARM汇编语言:caesar cypher

ARM汇编语言:caesar cypher,arm,character,Arm,Character,这是家庭作业 我必须将给定的字符串和偏移量作为参数,并创建该字符串的加密版本。这是我到目前为止所拥有的 .global cypher: stmfd sp!, {v1-v6, lr} @std mov v1, a1 @hold the string pointer in v1 bl strlen @get the length of the string in a1 add a1, a1, #1 @a

这是家庭作业

我必须将给定的字符串和偏移量作为参数,并创建该字符串的加密版本。这是我到目前为止所拥有的

.global
cypher:
    stmfd sp!, {v1-v6, lr} @std
    mov v1, a1             @hold the string pointer in v1
    bl strlen              @get the length of the string in a1
    add a1, a1, #1         @add null byte space to strlen
    mov v2, a1             @hold the length of space needed in v2
    bl malloc              @reserve space for new string in a1
    mov v3, #0             @initial index of new string
loop:ldr v4, [v1], #4      @load v4 with string pointer and increment by bytes
    add v5, v4, a2         @add the offset to the current character
    str v5, [a1, v3]       @store the new character in the new address
    add v3, v3, #4         @increment the index by a byte
    cmp v2, v3
    bne loop
    ldmfd sp!, {v1-v6, pc} @std     
    .end

我不知道如何正确地增加角色。如何向字符添加偏移量?我猜ascii字符需要增加?

您将循环迭代四个字节

下面是正确的:也是一个优化的:您不需要v3和v5

loop:ldrb v4, [v1], #1      @load v4 with string pointer and increment by bytes
    subs v2, v2, #1
    add v4, v4, a2         @add the offset to the current character
    strb v4, [a1], #1       @store the new character in the new address
    bne loop

    ldmfd sp!, {v1-v6, pc} @std     

是的。然后对于解密,只需减去正确的偏移量。但我可以看出,这就是您在代码中所做的。那么你的代码的结果是什么呢?测试的字符串是快速的棕色狐狸跳过懒惰的狗我得到的字符串是XHE UUICO BRSWN JOX NUMPW OVIR TLE LEZY HOG它似乎在更改字符之间跳过了3个字符我想这是因为你跳过了4个字节。你能试着把你的两套4换成1吗?没有成功。同样的事情也发生了,只是看起来向左移动了一个字符。仍然跳过中间的3个字符。另外,保存偏移量的第二个参数似乎给出了一个奇怪的偏移量,我目前正在使用固定偏移量4进行硬编码。你知道a2发生了什么吗?奇怪的是它跳过了3个字符。你确定你已经删除了所有4个?尝试将硬编码偏移量更改为7。然后呢?您的抵消功能实际上工作正常,我认为问题在于v3。