Vladimir Nani
Vladimir Nani

Reputation: 2874

How to get ASCII code of an character in assembly language?

I need to enter a string and to show that string like array of ASCII codes. How can i implement it in assembly language.

Upvotes: 2

Views: 14658

Answers (1)

Tom Anderson
Tom Anderson

Reputation: 47163

In assembly language, characters are already encoded in ASCII (or unicode or whatever). You work with characters as numbers.

What you need to be able to is to format numbers in their denary representation, for output. This is not specific to character codes.

There will almost certainly be library routines to do this, but it's not hard to do yourself. Basically, you write a loop which repeatedly extracts the lowest digit from the number (by taking the residue of the number modulo 10 - look for a MOD instruction), converts that into the character code for a digit (by adding 48) and adds it to a buffer, then divides the number by 10 to move on to the next digit. You repeat that until the number is zero.

Upvotes: 8

Related Questions