Arm Assembly Rasperry-Pi:将字符串转换为大写 [英] Arm Assembly Rasperry-Pi: Converting a string to Upper case

查看:93
本文介绍了Arm Assembly Rasperry-Pi:将字符串转换为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个程序,其中用户输入了他的名字,该程序应将所有小写字母都转换为大写字母:

我正在使用%s格式读取字符串:

  .textldr r0,= msjbl printfldr r0,=格式ldr r1,字符串bl scanf.数据.align 2msj:.asciz输入您的姓名:"格式:.asciz%s"字符串:.asciz" 

我尝试将每个字符减32,但是我认为字符串不是ascii数字格式.

有什么方法可以将整个单词转换为大写吗?

解决方案

这可能有效.我目前没有任何ARM资料.

 ;用'R0'中的字符串地址调用.upperString:1:ldrb r1,[r0],#1tst r1;用空终止符完成的字符串?bxeq lr;然后完成并返回cmp r1,#'a';少于一个?blo 1b;然后加载下一个字符.cmp r1,#'z';大于z?比1b;然后加载下一个字符.;大写的值.sub r1,r1,#('a'-'A');减去32.strb r1,[r0,#-1];放回内存.b 1b;下一个字符. 

至少这是一个很好的起点.就像 wallyk的代码一样,除了我假设以空终止的字符串代替了 pascal 类型的字符串.要称呼它,

  ldr r0,=字符串bl upperString 


变量

上面是终止为 ASCII 按照 .asciz 伪操作的字符串.字符串编码的另一种格式是Pascal类型.Pascal字符串的大小是 int大小;char data [size] ,并且没有空终止符.对于pascal字符串,循环机制将有所不同,但是对于ASCII编码,其核心( xor 0x20 sub'a'-'A')是相同的.

某些字符串编码是不同的.对于固定宽度的字符串,常数将更改.一些字符串使用转义机制,每个字形"或字母由不同数量的数据表示.在这种情况下,步进式"汇编器会发生变化.

最后,使用一个您经常想知道的'C'库,这是一个数字,这是一个标点符号等.在这种情况下,可以为每个字符的具有该字符属性的表建立索引.如果大写"和小写"的编码不是连续范围,则也可以使用此表方法.

希望变体部分对非剪切和粘贴"程序员有用.

I´m working on a program in which the user enters his name, and the program should convert all lower case letters to upper case:

I am using the %s format to read the string:

.text
 ldr r0,=msj
 bl printf
 ldr r0,=format
 ldr r1,string
 bl scanf



.data
.align 2
msj: .asciz "Enter you name:  "
format: .asciz "%s"
string: .asciz ""

I have tried substracting 32 to each character but I think the strings are not in ascii numbers format.

Is there any way I can convert the entire word to Upper Case?

解决方案

This might work. I don't have any of my ARM material with me at the moment.

; call with address of string in 'R0'.
upperString:
1: ldrb r1,[r0],#1
   tst  r1      ; finished string with null terminator?
   bxeq lr      ; then done and return
   cmp  r1,#'a' ; less than a?
   blo  1b      ; then load next char.
   cmp  r1,#'z' ; greater than z?
   bhi  1b      ; then load next char.

   ; Value to upper case.
   sub  r1,r1,#('a' - 'A') ; subtract 32.
   strb r1,[r0,#-1] ; put it back to memory.
   b    1b      ; next character.

At least it is a good starting point. This is like wallyk's code, except I have assumed a null-terminated string instead of a pascal type string. To call it,

   ldr r0,=string
   bl  upperString


Variants

Above is for a 'C' formatted 'NULL' (zero value) terminated ASCII string as per the .asciz pseudo-op. Another format of the string encoding is the Pascal type. A Pascal string is figuratively int size; char data[size] and there is no null terminator. The loop mechanics will be different for a pascal string, but the core (xor 0x20 or sub 'a' - 'A') is the same for ASCII encodings.

Some string encodings are different. For fixed width strings, the constants will change. Some strings use escape mechanisms and each 'glyph' or letter is represented by a different amount of data. The 'stepping' assembler changes in this case.

Finally, with a 'C' library you often want to know, is this a number, is this a punctuation, etc. In these case, a table for each character which has the property for that character can be indexed. You might also use this table approach, if the encoding for 'Upper' and 'Lower' case is not a contiguous range.

Hopefully the variants section is useful for non-'cut and paste' programmers.

这篇关于Arm Assembly Rasperry-Pi:将字符串转换为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆