好吧,因为我是ASM的新手,我在创建加密邮件的程序时遇到了一些问题。此时我只是想输入一个字符,输出应该是字母表中的char + 5个位置。
因此程序应该读取ASCII中的字符并向其中添加5,然后打印该字母。
例:输入:A 输出:F
它应仅适用于大写字母,因此每个字符应为&gt; = 65且<= 90。所以,如果我写'Z&#39;它应该从头开始字母并打印E&#39;。
到目前为止,我的代码看起来像这样:
li $v0, 8 #read_string
syscall #adresses char at $v0
li $v0, 5 #char ASCII (I GUESS IT SHOULD)
move $t0, $v0 #moves char(ASCII) to $t0
li $s0, 90
li $s1, 65
bgt $t0, $s0, le_string # checks if char(ASCII) > 90
ble $t0, $s1, le_string # checks if char(ASCII) < 65
li $s0, 5
add $t1, $t1, $s0 #char=char+5
move $t2, $t1 #moves encrypted char to $t2
li $v0, 4 #print_string
move $a0, $t2
syscall
LOG
25 / DEZ / 2015: 输入:A 输出:A
如果有人能帮助我,我真的很感激! 谢谢,
Rui(葡萄牙)
答案 0 :(得分:1)
如果您使用的是MIPS,则代码应如下所示:
.text
main:
li $v0, 8 # read_string
la $a0, textbuf # adresses of char at $a0
li $a1, 2 # length to read at $a1
syscall
la $t0, textbuf
lb $v0, 0($t0) # char ASCII (I GUESS IT SHOULD)
move $t0, $v0 # moves char(ASCII) to $t0
li $s0, 90
li $s1, 65
bgt $t0, $s0, le_string # checks if char(ASCII) > 90
nop # avoid instruction after branch begin executed even if jump is taken
blt $t0, $s1, le_string # checks if char(ASCII) < 65
nop # avoid instruction after branch begin executed even if jump is taken
li $s2, 5
li $s3, 26
add $t0, $t0, $s2 # char=char+5
ble $t0, $s0, nowrap_char # checks if encrypted char <= 90
nop # avoid instruction after branch begin executed even if jump is taken
sub $t0, $t0, $s3 # wrap the char
nowrap_char:
le_string:
move $t2, $t0 # moves encrypted char to $t2
la $t0, textbuf
li $v0, 4 # print_string
sb $t2, 0($t0) # put the encrypted char
la $a0, textbuf
syscall
li $v0, 10 # exit
syscall
.data
textbuf:
.space 2