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

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

问题描述

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

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

.textldr r0,=msj打印输出ldr r0,=格式ldr r1,字符串bl扫描.数据.align 2msj: .asciz "请输入您的姓名:"格式:.asciz "%s"字符串:.asciz ""

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

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

解决方案

这可能会奏效.我目前没有任何 ARM 材料.

<代码>;使用R0"中的字符串地址调用.上字符串:1: ldrb r1,[r0],#1tst r1 ;用空终止符完成的字符串?bxeq lr;然后完成并返回cmp r1,#'a' ;小于一个?血液 1b ;然后加载下一个字符.cmp r1,#'z' ;大于z?bhi 1b ;然后加载下一个字符.;大写的值.sub r1,r1,#('a' - 'A') ;减去 32.strb r1,[r0,#-1] ;把它放回记忆中.b 1b ;下一个字符.

至少这是一个很好的起点.这就像 wallyk 的 代码,除了我假设了一个 空终止 字符串而不是 pascal 类型字符串.调用它,

 ldr r0,=stringbl 上字符串


变体

以上是针对 'C' 格式的 'NULL'(零值)终止 ASCII根据 .asciz 伪操作的字符串.字符串编码的另一种格式是 Pascal 类型.帕斯卡字符串象征性地为 int 大小;char data[size] 并且没有空终止符.pascal 字符串的循环机制会有所不同,但核心(xor 0x20sub 'a' - 'A')对于 ASCII 编码是相同的.>

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

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

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

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天全站免登陆