views:

84

answers:

1

I have this code on pdp-11

tks = 177560
tkb = 177562
tps = 177564
tpb = 177566
lcs = 177546
. = torg + 2000

main:   mov #main, sp
        mov #kb_int, @#60
        mov #200, @#62
        mov #101, @#tks
        mov #clock, @#100
        mov #300, @#102
        mov #100, @#lcs

loop:   mov @#tks,r2
        aslb r2
        bmi loop
        halt

clock:  tst bufferg
        beq clk_end
        mov #msg,-(sp)
        jsr pc, print_str
        tst (sp)+
        clr bufferg
        bic #100,@#tks
        clr @#lcs
clk_end:rti

kb_int: mov r1,-(sp)
        jsr pc, read_char
        movb r1,@buff_ptr
        inc buff_ptr
        bis #1,@#tks
        cmpb r1,#'q
        bne next_if
        mov #0, @#tks
next_if:cmpb r1,#32.
        bne end_kb_int
        clrb @buff_ptr
        mov #buffer,-(sp)
        jsr pc, print_str 
        tst (sp)+
        mov #buffer,buff_ptr
end_kb_int:
        mov (sp)+,r1
rti


;#############################
read_char:
        tstb @#tks
        bpl read_char
        movb @#tkb, r1
        rts pc
;#############################
print_char:
        tstb @#tps
        bpl print_char
        movb r1, @#tpb
        rts pc
;#############################
print_str:
        mov r1,-(sp)
        mov r2,-(sp)
        mov 6(sp),r2
str_loop:
        movb (r2)+,r1
        beq pr_str_end
        jsr pc, print_char
        br str_loop
pr_str_end:
        mov (sp)+,r2
        mov (sp)+,r1
        rts pc

. = torg + 3000
msg:.ascii<Something is wrong!>
    .byte 0
    .even
buff_ptr: .word buffer
buffer: .blkw 3
bufferg: .word 0

can somebody explain please which part of the code can change bufferg(last row)? thanks in advance

A: 

I found in this program three basic functional blocks:

  1. reading of characters from keyboard to the buffer (kb_int:, read_char:, etc)
  2. printing of chars (print_char:, print_str:)
  3. monitoring of correctness of read/write above operations (clock:).

I suppose that bufferg is guard word as it follows the segment where data is read from keyboard (bufferg's is a word after 3 words of buffer - the last two lines). So, if something goes wrong (too many input chars or too slow printing) the bufferg becomes filled with some non-zero value. This is caught in clock: (which is apparently a timer interrupt handler) - tst bufferg tests for zero value and if it's not equal to zero (it's default value) the message (msg:) "Something is wrong!" is printed and bufferg is reset to zero clr bufferg.

So, the short answer to the question will be: bufferg can be changed either in movb r1,@buff_ptr or in clr bufferg.

Pmod