assemblybootloadersic

sicxe assembly language programming


the following are assembly language codes of an sic/xe machine....

     clear a
     ldx #128
loop jsub getc
     rmo a,s
     shift s,4
     jsub getc
     addr s,a
     stch 0,x
     tixr x,x
     j loop



getc td input 
    jeq getc
    rd input 
    comp #4     ;if input is 4 then eof
    jeq 80      ;jump to start of program
    comp #48    ; compare to charcter 0
    jlt getc    ;skip charcters less than 0
    sub #48     
    comp #10    ;if result is less than 10, conversion is complete
    jlt return 
    sub #7      ;for hex digits A through F
return rsub
input byte x'F1'

this is a bootstrap loader...the purpose of this programme is to read from device F1 and store the input at address starting from 80...now my question is that when the why do we need to do shift s,4...when we take an input once, we find its original value from its ascii value and then send it to 'loop' to store it...from the programme it appears that first only half byte of chatacter is sent to loop and then the other...if this is the fact then in a first there would be first half byte of charcter and so the ascii operations on the first half will not give us the real value of input...also when the programme returns to 'getc' to get the other half byte will not the other character in the list be read instead...the following is a line from the same book for help...

each byte of the code to be loaded is on device F1 as two hexadecimal digits  

Solution

  • That code converts a number encoded in an ASCII string to a byte value.

    So, given the string 'A5' it will store the number 165 into a byte in memory.

    It needs to do two reads for each byte value. (as you can see, there are two characters in the string 'A5', which are 'A' and '5'.

    The getc routine reads the first character. In my example this is 'A', which has an ASCII value of 65 (41 hex). The routine subtracts 48, and then 7 again. 65-48-7 = 10, which is the decimal notation of the hex digit A.

    The loop then shifts this value 4 places, resulting in the value of 160'. That's because the first character we read was the higher-order byte of the two-byte string.

    The next time getc is called, it reads the character '5', which has a code of 53. 53-48 is 5.

    The loop then adds 5 to the previously-stored value of 160, giving the correct total of 165.

    So again, that code snippet converts an ascii-encoded hex number into a byte value. You need two characters to make up a byte value.