1

I'm using easy68k, and I have a string, and I want to add a number to every digit so it ends up being a different string. Is there a command that lets me target the specific bytes in a string?

for example:

        ORG $1000
START:             
        MOVE.B  str,D0
        ADD.B   #$20,D0
        MOVE.B  D0,str

str     DC.B   'ASDF'
        END    START     

I'm trying to make "ASDF" into "asdf", but my current code only allows me to target the first byte of "ASDF" which is "A", so my resulting string is now "aDSF", how do I make it so the byte thing move onto D,S, and F? is there a specific command to do this?

Thanks in advance

ay lmao
  • 305
  • 2
  • 5
  • 17

1 Answers1

2

A bit can only be 0 or 1. 0 and 1 are the only digits in base2 numbers.

xor is an add without the carry from low bits to high bits. Does that help? The question body doesn't seem to match the title, though.


Your terminology is very mixed up, unfortunately. Probably a lot of technical meaning was lost in translation from your native language.

  • A "digit" usually means a decimal or hex digit: 0-9 or 0x0-0xF

  • A "bit" always means a single 0 or 1 value. The title of this question doesn't match what you seem to be asking in the body.

  • A "string" usually means a sequence of ASCII (or UTF8, or UTF16) bytes that encodes a printable string. e.g. char *str="Hello World!"; (i.e. not arbitrary binary.) You can say "a string of bytes", which seems to be what you're talking about.

  • An "array" is a sequence of elements, like uint8_t arr={0xA2, 0x02, 0x15, 0xFF}; This seems to be what you're talking about: an array of bytes.

Please edit your question to retitle it if you didn't intend to ask about individual bits.


It sounds more like you have a sequence of bytes, and you want to add the same value to each byte. You'll need a loop to do that, since there is no SIMD instruction set for m68k, accoding to google. A SIMD instruction could do multiple single-byte adds in parallel, on each byte of a vector register. (like x86's PADDB vector instruction, which you could use after broadcasting 0x20 to all 16 elements of a vector register.)

A SIMD add is an add with breaks in the carry from low bits to high bits, at the element boundaries.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Thank you, yeah it seems like my terminology was really wrong, I have changed it to correct terminology in my post and added an example, I'm wondering how to move the byte so I can target every single byte instead of just the first one in the string – ay lmao Jan 22 '16 at 20:14
  • @JoeyZhang: If you already know all the bytes are alphabetic characters, you can use `OR` or `AND` to set or clear bits in multiple bytes at once. (Or `XOR` to toggle). This is a simple form of [SWAR](https://en.wikipedia.org/wiki/SWAR), and works because it can't generate a carry that propagates into the next byte. If you know the bytes are all upper-case, you can use an `add` instead of an `or`, since you know it won't carry. Other than that, m68k doesn't have SIMD instructions. – Peter Cordes Jan 22 '16 at 21:05
  • Other than that, this is assembly language. You often have to loop over bytes in a string, because there aren't whole-string instructions. – Peter Cordes Jan 22 '16 at 21:06