通过内存迭代编辑每个字节 [英] Iterate through memory editing each byte

查看:134
本文介绍了通过内存迭代编辑每个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写汇编code,提示为小写字符的字符串,然后用户输出与所有大写字符相同的字符串。我的想法是通过在开始一个特定的地址字节进行迭代并减去20H(变成小写为大写)的每一个,直到我达到一个特定值的字节。我与大会相当缺乏经验,所以我不知道这样一个循环的语法会是什么样子。

I'm writing assembly code that prompts the user for a string of lower-case characters then outputs the same string with all UPPER-CASE characters. My idea is to iterate through the bytes starting at a specific address and subtract 20H (turns a lower case to upper-case) from each one until I reach a byte with a specific value. I'm fairly inexperienced with Assembly so I'm not sure what the syntax for such a loop would look like.

任何人都可以提供一些样品code或直接我在那里我能找到这样的语法的例子吗?

Can anyone provide some sample code or direct me where I can find examples of such syntax?

任何帮助是极大AP preciated!

Any help is greatly appreciated!

推荐答案

通常情况下,一个字符串用一个零(0x00十六进制)。假设这是你选择做什么,这里的一些样品code。我不知道你使用的汇编,或者甚至是语法,但这个86 code应在MASM工作:

Typically, a string is terminated with a null (0x00 in hex). Assuming this is what you choose to do, here's some sample code. I'm not sure which assembler you're using, or even which syntax, but this x86 code that should work in MASM:

mov cl, 0             ; cl is the counter register, set it to
                      ; zero (the first character in the string)

start:                ; Beginning of loop
  mov al, bytes[cl]   ; Read the next byte from memory

  cmp al, 0           ; Compare the byte to null (the terminator)
  je end              ; If the byte is null, jump out of the loop

  sub al, 20h         ; Convert to upper case
                      ; A better solution would be: and al, 0DFh

  ; Output the character in al

  add cl, 1           ; Move to the next byte in the string
  jmp start           ; Loop
end:

这篇关于通过内存迭代编辑每个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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