Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code complies and works as intended except for the fact that it's not returning the new value in AL reg that was created after an "and" or "or" statement.

What I have tried:

program charConverter;
#include( "stdlib.hhf" );
static
iValue : byte;

	//This Procedure converts UPPERCASE letters to lowercase and vice versa.
	procedure converter( myCharacter : byte ); @nodisplay; @noframe;
	
	static
    returnChar : byte;
    iTemp : int16;
    iReturnAddress : dword;
    iRegisterValue : 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
	// preserve registers --- EBX place on stack after pops
	mov( EBX, iRegisterValue );
	// acquire parameters on the stack
	pop( iReturnAddress );
	pop( iTemp ); // this is junk to align the stack
	pop( iTemp ); // this is myCharacter
	mov( iTemp, BX );
	mov( BL, myCharacter );
	// push back the return address
	push( iReturnAddress );
	// preserve registers --- EBX
	push( iRegisterValue );
	
	// perform subtask
	mov( cBigA, BL );
	mov( cBigZ, BH );
	mov( cLittlea, CL );
	mov( cLittlez, CH );
	mov( cNumZero, DL );
	mov( cNumNine, DH );				
	mov( AL, myCharacter );
	
	cmp( AL, DL );				//Compare myCharacter (AL) to "0" (DL)
	jg IsItANumber;
	jmp ItsSomethingElse;
	
	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 );
	jmp ExitSequence;
	
	ItsANum:
	mov( $21, AL );
	jmp ExitSequence;
	
	ItsUPPERCASE:
	and( %1101_1111, AL );
	jmp ExitSequence;
	
	ItsLowercase:
	or( %0010_0000, AL );
	jmp ExitSequence;
  	
  	ExitSequence:
	// exit sequence
	// pop all preserved registers --- BX
	pop( EBX );
	// send return value to AL
  	ret();
  	end converter;
  	
begin charConverter;
stdout.put( "Feed Me: " );
// always a good idea to flush buffer before reading
stdin.flushInput();
stdin.getc();
mov( 0, BX ); 	
mov( iValue, BL );
push( BX );
mov( 0, BX ); 	
push( BX );
call converter;
stdout.put( "converted that's " );
stdout.putc( AL );
stdout.put( nl );
end charConverter;
Posted
Updated 6-Aug-18 20:44pm

1 solution

The function is returning the result in AL. But EAX is the general working directory and must be saved therefore elsewhere when doing anything else inbetween; especially when calling functions.

Untested (I don't know HLA well):
convChar : byte;
call converter;
// Save AL to a variable
mov( AL, convChar );
// This will modify EAX
stdout.put( "converted that's " );
stdout.putc( convChar );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900