2014-11-30 7 views
0

이 사이퍼 시저 숙제 내가 매개 변수로 주어진 문자열과 오프셋을 가지고 문자열의 암호화 된 버전을 만들 필요가ARM 어셈블리 언어 :

입니다. 여기 내가 지금까지 가지고있는 것입니다

.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 

실제로 문자를 올바르게 늘리는 방법을 알아내는 데 어려움이 있습니다. 문자에 오프셋을 추가하는 방법 (아스키 문자가 증가해야한다고 추측합니다)

+0

예 그들은 할 수 아래

은 "올바른"하나입니다. 그런 다음 암호 해독을 위해 올바른 오프셋을 뺍니다. 그러나 나는 당신이 당신의 코드에서 무엇을하는지 볼 수 있습니다. 그렇다면 코드의 결과는 무엇입니까? – Phil

+0

테스트 된 문자열은 "LAZY DOG의 빠른 갈색 폭스 점프"입니다. 내가 얻는 문자열은 "XHE UUICO BRSWN JOX NUMPW OVIR LEZY HOG"입니다. 문자를 변경하는 사이에 3 문자를 건너 뛰는 것 같습니다. – lilscarecrow

+0

4 바이트를 건너 뜁니다. # 4에서 # 1로 두 세트를 변경해 볼 수 있습니까? – Phil

답변

0

루프를 4 바이트 반복합니다. (: 당신이 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