0

I am trying to make a subroutine that takes inputs from another subroutine and turn them into lowercase letters.

`






Load StringAddress
Store AddressString
JnS subInputString
JnS subToLower
JnS subPrintString

Halt

StringAddress,  HEX 287 / This is the starting address of the string

////////////////////////////////////////////////////////////////////////
// Task 2.2 - Subroutine for printing strings                           
////////////////////////////////////////////////////////////////////////

subPrintString, HEX 000 / subroutine start
        Load StringAddress
                Store Temp
                
LoopExit, LoadI Temp
          Skipcond 800
          Jump EndOut
          Output
          Load Temp
          Add One
          Store Temp
          Jump LoopExit

EndOut, Load NewLine
    JumpI subPrintString

One, DEC 1
NewLine, HEX 0A

Temp, HEX 0
CurrentCharacterADR, ADR TheName
TheName, HEX 41
         HEX 68
         HEX 6D
         HEX 61
         HEX 64
         HEX 20
         HEX 4D
         HEX 75
         HEX 69
         HEX 7A
         HEX 7A
         HEX 0


////////////////////////////////////////////////////////////////////////
// Task 2.3 - Subroutine for string input                               
////////////////////////////////////////////////////////////////////////

subInputString, HEX 000 / subroutine start
stringIn,       Input
                Skipcond 800
                Jump EndOut2
                StoreI AddressString
                Load AddressString
        Add One2
                Store AddressString
                Jump stringIn
                
EndOut2, Load NewLine2
     JumpI subInputString

NewLine2, HEX 0A
One2, DEC 1
AddressString, HEX 0              
////////////////////////////////////////////////////////////////////////
// Task 2.4 - Subroutine to convert to lower case                       
////////////////////////////////////////////////////////////////////////

subToLower, HEX 000     / subroutine start
toLowerLoop,    Load AddressString
        Add stringIterate
        Store stringIndex
        Clear
                Add stringIndex
                Skipcond 400
                Jump lowerConversion
                JumpI subToLower
                
lowerConversion, Add upperToLower
             Output
                 Load stringIterate
         Add One3
         Store stringIterate
         Jump toLowerLoop           
            
One3, DEC 1
lowerCase, HEX 0
upperToLower, HEX 20
lowerString, HEX 0
stringIndex, HEX 0
stringIterate, DEC 0

For example, if I input in 'GO' in unicode (and then 0 in hexadecimal or decimal to stop the input subroutine), the expected output is 'go' but instead the output is still 'GO'. I don't understand why it's still printing in uppercase?

RedRazor
  • 1
  • 1
  • Have you tried debugging via single step? Verify between each instruction the program state including control flow. Program state means that register(s) or memory have been updated as expected and control flow means that the proper next instruction executes. – Erik Eidt Dec 12 '22 at 00:27
  • @ErikEidt Yes, I have, at the 'subToLower' subroutine, after Skipcond 400, it exits the subroutine, meaning it never jumps to 'lowerConversion' since it detects AC = 0. – RedRazor Dec 12 '22 at 01:23
  • Ok, so working backwards just a bit, what is in the Accumulator when the Skipcond executes? – Erik Eidt Dec 12 '22 at 01:50
  • Considering it loads the 'addressString' it should be 'GO' in unicode i guess? And it ends with either a hexadecimal or decimal '0' – RedRazor Dec 12 '22 at 02:05
  • Do you know how strings work? They are data structures, effectively an array of characters, that live in memory and are referenced by the address of the first element. So addressing and dereferencing are necessary to work strings. – Erik Eidt Dec 12 '22 at 02:10
  • Right, now I'm confused. – RedRazor Dec 12 '22 at 02:11
  • Ok, me too, regarding your program. However, you can chat me at [codementor.io](https://www.codementor.io/@erikeidt) and I'll happily discuss in chat as I can. – Erik Eidt Dec 12 '22 at 02:13
  • The `HEX` statements under the label `TheName` is a string. If you add 32 to each byte that's greater than `0x40` but less than `0x5B` you'll get the same string but in lower case. You can loop through each byte, compare it to those numbers listed above, and add 32 if it falls in that range, Stop when the byte you read is zero. – puppydrum64 Dec 15 '22 at 13:47

0 Answers0