The diskrw program.


R. Clayton (rclayton@monmouth.edu)
Tue, 31 Oct 2000 15:24:10 -0500 (EST)


A couple of people have asked about the programs their operating system is
running. Below is the more interesting of the two program from pa2-diskrw.dsk.

The programs are written in a simple, made-up assembly language. In most
cases, the instruction

  op a b

can be though of as the c/c++ statement

  a op= b

The * operator is the same as c/c++: *a means follow the pointer a and return
the value you find.

There are two points of interest about this program. First, the tty id and
word count are keep in cpu registers. If an os isn't saving and restoring user
process state correctly, this program will not work because the id or count (or
both) are will be corrupted.

Second, if any disk io operation fails, the program exits. If an operating
system is not returning the proper system-call values, the user process will
most likely interpret the values as errors and exit prematurely

        ; System calls.

          same exit 1
          same open 3
          same close 4
          same read 5
          same write 6

        ; Devices.

          same tty 1

        ; Status.

          same ok 1

        ; The tty id is stored in register 6.

          same ttyid 6

        ; The count of words written is stored in register 5.

          same wordcnt 5

        ; Open a connection to the disk.

          move 0 open
          move 1 tty
          sysc

        ; If something bad happened, bail out.

          cmpr 0 ok
          bne out

        ; Save the disk id.

          move ttyid *1

        ; Initialize the data-write counter to 0.

          move wordcnt 0

        ; Read the last block on the disk.

loop move 0 read
          move 1 *ttyid
          move 2 data
          move 3 63
          sysc

        ; Bail if something bad happened.

          cmpr 0 ok
          bne close

        ; Write the base register plus the counter to the next space in the
        ; data block.

          move 7 data
          add 7 *wordcnt
          move *7 *15
          add *7 *wordcnt

        ; Write the block back to disk.

          move 0 write
          move 1 *ttyid
          move 2 data
          move 3 63
          sysc

        ; Bail if something bad happened.

          cmpr 0 ok
          bne close

        ; Increase the data-write counter bail if 32 values have been written.

          add wordcnt 1
          cmpr wordcnt 32
          blt loop

        ; Close the disk connection

close move 0 close
          move 1 *ttyid
          sysc

        ; See ya.

out move 0 exit
          sysc

        ; Where the disk data gets read and written.

data word 1 2 3 4 5 6 7 8
          word 9 10 11 12 13 14 15 16
          word 17 18 19 20 21 22 23 24
          word 25 26 27 28 29 30 31 32

        done



This archive was generated by hypermail 2.0b3 on Mon Dec 18 2000 - 13:30:06 EST