Since char values in HLA are just numeric equivalencies based on their ASCII cod
ID: 3920930 • Letter: S
Question
Since char values in HLA are just numeric equivalencies based on their ASCII code table value, you can manipulate character like you do any other numerical value.
For this program, I would like you to create a function which returns a character value based on a character parameter as shown below:
So in other words, UPPERCASE letters should become lowercase, lowercase letters should become UPPERCASE, number characters should be come an exclamation mark and all other characters should turn into an underscore. The converted letter should be stored in AL.
Write an HLA Assembly language program that implements the following function:
procedure converter( myCharacter : byte ); @nodisplay; @noframe;
Your function should return in AX the converted character value, as shown in the chart above.
(Hint: Since the run-stack doesn't allow for a byte-sized argument to be pushed and popped, you will need to envelope the argument in a larger eight bit argument. The converted letter should be stored into AL)
Feed Me: I
converted that's i
Feed Me: g
converted that's G
Feed Me: 1
converted that's !
Feed Me: #
converted that's _
Here is what I have so far:
program charConverter;
#include( "stdlib.hhf" );
//This Procedure converts UPPERCASE letters to lowercase and vice versa.
procedure converter( myCharacter : byte ); @nodisplay; @noframe;
static
myCharacter : byte;
iReturnAddress : dword;
cBigA : byte := $41; // A = hex 41
cBigZ : byte := $5A; // Z = hex 5A
cLittlea : byte := $61; // a = hex 61
cLittlez : byte := $7A; // z = hex 7A
cNumZero : byte := $30; // 0 = hex 30
cNumNine : byte := $39; // 9 = hex 39
begin converter; //Begin converter
// entry sequence
// acquire parameters on the stack
pop( iReturnAddress );
pop( myCharacter );
pop( cBigA );
pop( cBigZ );
pop( cLittlea );
pop( cLittlez );
pop( cNumZero );
pop (cNumNine );
// push back the return address
push( iReturnAddress );
// preserve registers --- NONE
// perform subtask
mov( cBigA, BL );
mov( cBigZ, BH );
mov( cLittlea, CL );
mov( cLittlez, CH );
mov( cNumZero, DL );
mov( cNumNine, DH );
stdout.put( "Feed Me: " );
// always a good idea to flush buffer before reading
stdin.flushInput();
stdin.getc();
mov( AL, myCharacter );
cmp( AL, DL ); //Compare myCharacter (AL) to "0" (DL)
jg IsItANumber;
IsItANumber:
cmp( AL, DH );
jl ItsANum;
jmp IsItUPPERCASE;
IsItUPPERCASE:
cmp( AL, BL );
jg IsItStillUPPERCASE;
jmp ItsSomethingElse;
IsItStillUPPERCASE:
cmp( AL, BH );
jl ItsUPPERCASE;
jmp IsItLowercase;
IsItLowercase:
cmp( AL, CL );
jg IsItStillLowercase;
jmp ItsSomethingElse;
IsItStillLowercase:
cmp( AL, CH );
jl ItsLowercase;
jmp ItsSomethingElse;
ItsSomethingElse:
mov( $5F, AL );
ItsANum:
mov( $21, AL );
ItsUPPERCASE:
and( AL, %1101_1111 );
ItsLowercase:
or( AL, %0010_0000 );
stdout.put( "converted that's " );
stdout.putc( AL );
stdout.put( nl );
ret();
end converter;
begin charConverter;
call converter;
end charConverter;
However, my code does not compile, getting a duplicate symbol definition error. Please advise
Letter Return Value A-Z a-z a-z A-Z 0-9 ! all other letters _Explanation / Answer
Hi Sir, the duplicate error is because of this:-
In your procedure converter, you are already passing myCharacter : byte as a parameter. Then again you are declaring a variable myCharacter : byte; inside the same procedure having the same name as that of the parameter being passed. This is duplicate variable, and so because of this you are getting "duplicate symbol definition error". Change the myCharacter : byte; to say myCharacter1 : byte; so that duplicate symbols wont be present inside the procedure.
Please let me know in case of any clarifications required. Thanks!