BobtheBuilder
BobtheBuilder

Reputation: 3

How to get to the ascii code of a character in a string MASM Assembly

Say I have a string named abc initialized as "something". To get the first character of this string I would do abc[0] which would show 's'. Is there some notation that I could use to get the ascii code for 's' which is 73h? I'm using MASM.

I'm trying to subtract the ascii code from a character to form a different character. So if 's' is 115d, I want to subtract 4 so it's 111d so then it becomes the letter 'o'.

Upvotes: 0

Views: 8250

Answers (1)

Michael
Michael

Reputation: 58427

If you have the ASCII string "something" and you read the first byte from that string you'll get 115, which also equals 's', which also equals 73h. There's no conversion necessary because it's just a byte with some value. Whether you want to view that value as 115, 's' or 73h doesn't really become relevant until you want to print it.

.data
something db "something",0

.code
mov al,[something]    ; al = 115 / 73h / 's'
sub al,4              ; al = 111 / 6Fh / 'o'

Upvotes: 3

Related Questions