; Convert intext to upper case with some OS 'flavor' JMP UCstart intext: DB "In Text !@#" ; Variable DB 0xFF ; String terminator ucA: DB 'A' ; upper case A value ucZ: DB 'Z' ; upper case Z value lca: DB 'a' ; lower case a value lcz: DB 'z' ; lower case z value lcuc: DB 0d ; Will hold lc to uc difference ; not needed outbuf: DB 0xE8 ; output buffer start memloc UCstart: ; Calculate the difference between lca and ucA values ; Store result in lcuc MOV A, [ucA] MOV B, [lca] SUB B, A MOV [lcuc], B ; For remainder ; reg C has the memloc of the current char ; reg B has the current output offset ; reg A has the current char ASCII value MOV C, intext ; Get 1st char of intext memloc MOV B, 0x00 ; Set output buffer offset to 0 loopch: MOV A, [C] ; Get next intext char value CMP A, 0xFF ; Check if string terminator JNE convch ; If not convert the character HLT ; normal termination (i.e., string terminator) convch: CMP A, [lca] ; Is char >= lc a? JB showch ; If not show the char CMP A, [lcz] ; Is char <= lc z? JA showch ; If not show the char SUB A, [lcuc] ; Subtract to convert to upper case showch: MOV [OBchar], A ; 'Pass' the ASCII character MOV [OBloc], B ; 'Pass' the buffer offset CALL OBch ; Have the 'OS' output the character INC B ; increment output buffer memloc INC C ; increment intext memloc JMP loopch ; process next character ; OS code OBbeg: DB 0xE8 ; Output buffer begin location OBend: DB 0xFF ; Output buffer end location OBchar: DB 0x00 ; Passed ASCII character to output OBloc: DB 0x00 ; Passed output buffer offset OBch: PUSH A ; preserve reg A value PUSH B ; preserve reg B value MOV A, [OBchar] ; get the 'passed' char in reg A MOV B, [OBloc] ; get the 'passed' buffer offset ADD B, [OBbeg] ; Calc output buffer location CMP B, [OBbeg] ; Check if location >= OB begin loc JB OBErr ; If not jump to error CMP B, [OBend] ; Check if location <= OB end loc JA OBErr ; if not jump to error MOV [B], A ; put character into output buffer POP B ; restore reg B POP A ; restore reg A RET OBErr: ; Invalid output attempted ; a 'real' OS would have the app exit with an error code MOV B, [OBbeg] ; Get loc of output buffer MOV [B], '*' ; put an * to indicate an issue HLT ; error termination