臂组件凯撒密码加密

时间:2015-09-30 07:05:54

标签: assembly arm caesar-cipher rot13

我对手臂组装非常新,我正在使用武器进行学校项目。我有很多问题。

  1. 我需要从txtfile读取多行,每行都有一个字符串,最多需要85个字节(每行)。我的程序只读取第一行,我不知道如何读取文件的其余部分。
  2. 我必须从每一行中取出每个字符,如果字符值我称之为“a”((a> = 65&& a< = 77)||(a> = 97& & a< = 109))。如果((a> = 78&& a< = 109)||(a> = 110&& a< = 122)),我必须减去13。如果(a == 32)那么我打印出空格并移动到下一个字符。我不明白如何使用分支机构这样做...
  3. 循环逐个字符处理并将字符输出到stdout中。 到目前为止,这是我的代码...我花了几天时间这个小时,我无法绕过这个。到目前为止我只接触过java。

    .equ SWI_Open, 0x66 @open a file
    .equ SWI_Close,0x68 @close a file
    .equ SWI_PrChr,0x00 @ Write an ASCII char to Stdout
    .equ SWI_PrStr, 0x69 @ Write a null-ending string
    .equ SWI_PrInt,0x6b @ Write an Integer
    .equ SWI_RdInt,0x6c @ Read an Integer from a file
    .equ SWI_RdStr, 0x6a @ Read string from file
    .equ Stdout, 1 @ Set output target to be Stdout
    .equ SWI_Exit, 0x11 @ Stop execution
    .global _start
    .text
    _start:
    
    ldr r0,=InFileName @ set Name for input file
    mov r1,#0 @ mode is input
    swi SWI_Open @ open file for input
    ldr r1,=InFileHandle
    str r0,[r1]
    ldr r7,[r1]
    ldr r1,=array
    mov r2,#85
    swi SWI_RdStr @stores the string into =array 
    
    mov r5,#0 @r5 is index
    
    loop: @processes a single char then loops back
    cmp r5,r2 @r2 is 83
    bge procstop
    ldrb r4,[r1,r5] @loads the character value from =array[r5] into r4
    
    cmp r4,#77
    ble add
    cmp r4,#65
    bge add
    
    cmp r4,#97
    bge add
    cmp r4,#109 
    ble add
    
    cmp r4,#78
    bge sub
    cmp r4,#90
    ble sub
    
    cmp r4,#110
    bge sub
    cmp r4,#122
    ble sub
    
    add:
    add r4,r4,#13
    
    sub:
    sub r4,r4,#13
    
    mov r0,r4
    swi SWI_PrChr
    
    strb r4,[r1,r5]
    add r5,r5,#1
    B loop
    procstop:
    
    mov r0,#Stdout
    swi SWI_PrStr
    swi SWI_Exit
    
    .data
    InFileName: .asciz "lab4.txt"
    EndOfFileMsg: .asciz "End of file reached\n"
    ColonSpace: .asciz": "
    NL: .asciz "\n " @ new line
    array: .skip 85
    .align
    InFileHandle: .word 0
    
    
    .end
    

1 个答案:

答案 0 :(得分:0)

啊我明白了。我不知道为什么我不早点想到这个。不需要比较所有这些,只需要每次比较一个,从最小的比较到最大的比较,基本上是一个if / else if语句链