0

currently working on a code in pdp-11 but i get this error "odd word adress" so i searched in the internet and found this :An odd address error : which occurs if a register used in a word autoincrement or autodecrement instruction becomes odd. and i didn't understand what they mean! can someone help me ?

      main:   mov #0,r0  ; r0 is the index of the Moves array
        mov #0,r1  ; r1 is the index of the Cols of the Board
        mov nCols,r3  ; r3 is the label of the Rows of the Board
        mul nRows-1,r3
        .even
        add #Board,r3
        movb r3,FR  ;FR is the first row in board

even:   movb r1,r5       ; here we are in even row 
        add Moves(r0),r5
        movb #0,r4
        div nCols,r4
        mov r5,sharet
        mul nCols,r4
        sub r4,r3   
        br chick_row

chick_row:mov r3,help   ;here we gonne chick if the row is even or uneven
        mov FR,r5
        sub help,r5
        mov #0,r4
        div nCols,r4          
        mov r4,r5
        mov #0,r4
        div #2,r4           
        cmpb #0,r5
        beq Reven
        br  Runeven  


uneven: mov nCols,r5  ;now we are in uneeven row and we want to add the moves and see if it leads us to even or uneven
        sub r1,r5
        sub #1,r5
        add Moves(r0),r5
        mov #0,r4
        div nCols,r4
        mov r5,sharet
        mul nCols,r4
        sub r4,r3
        br chick_row



Reven:  mov sharet,r1       
        br findC             


Runeven:mov nCols,r1     
        sub sharet,r1
        sub #1,r1
        br findC


loopEnd:add #1,r0        ;we increased r0 and now we are going to chick if the current row is even or not
        mov r3,help      ;here we gonne chick if the row is even or uneven
        mov FR,r5
        sub help,r5
        mov #0,r4
        div nCols,r4          
        mov r4,r5
        mov #0,r4
        div #2,r4            
        cmpb #0,r5
        beq even
        br  uneven

findC:  mov r3,currentCell                        ; find the current cell after adding the current move
        add r1,currentCell
        ; check the value of the current cell
        cmpb currentCell,'L
        beq isLadder
        cmpb currentCell,'S
        beq isSnake
        cmpb #currentCell,#Board
        blo errorC 
        add currentCell,Score
        br  loopEnd


isLadder:mov r3,FR
        sub #Board,FR
        cmpb FR,nCols
        blo errorLadder
        sub nCols,r3
        mov r3,currentCell
        add r1,currentCell
        cmpb currentCell,'L
        beq isLadder
        add currentCell,Score
        br  loopEnd

isSnake:mov r3,r4
        mov nCols,r5
        mul nRows-1,r5
        add #Board,r5
        sub r5,r4
        cmpb r4,nCols
        blo errorSnake
        add nCols,r3
        mov r3,currentCell
        add r1,currentCell
        cmpb currentCell,'S
        beq isSnake
        add currentCell,Score
        br  loopEnd


errorLadder:mov #1,Score
            br Failure

errorSnake: mov #0,Score
            br Failure

errorC:     mov #2,Score
            br Failure

gameEnd:    mov #Board,r4     ; check if the game ended successfully..
            add nCols,r5
            sub #1,r5
            cmpb currentCell,r5
            beq Success
            mov #3,Score
            br Failure

Failure: mov #'F,Output
        halt
Success: mov #'S,Output
        halt



.=torg + 2000
currentCell:   .word 0
lastRow:       .word 0
FR:            .word 0 
help:          .word 0
sharet:        .word 0

.=torg + 5000

nCols:  .word 5
nRows:  .word 3
Board:  .byte 2,  3, 'S, 'L,  0
    .byte 5, 'L,  6, 'S,  6
    .byte 1, 'L, 'S,  1, 'L

Moves:  .byte 4, 5, 4, '@

; Outputs
.even 
Output:   .blkw 1
Score:    .blkw 1
numMoves: .blkw 1
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
jasmine
  • 11
  • 4
  • 3
    Odd, as in not even. Not a multiple of 2. You must access words aligned to 2 bytes. – Jester Dec 10 '16 at 00:47
  • If you access multiple bytes at once in a piece of memory where the address of what you are reading/writing is odd (low bit set of address), you will get errors like this. – Michael Dorgan Dec 10 '16 at 01:06
  • i tried fixeing the problem by aading" .even" which means start in even byte but it didn't work i also used movb instead of mov also didnit work 1 – jasmine Dec 10 '16 at 08:21
  • i get the mistake in (add #board,r3 ) the 6 row ! – jasmine Dec 10 '16 at 08:24

1 Answers1

1

The pdp-11 integer instructions handle 8bit bytes or 16bit words. All word accesses must be on even addresses. A word access on an odd address will cause an odd address trap and abort the instruction.

In other terms: word accesses must be word-aligned on a pdp-11.

So in the example

mov #1000,r0       ; r0 set to 1000
tstb (r0)+         ; r0 incremented to 1001
tst (r0)           ; <-- odd address trap here

the processor will trap on the tst instruction because a word access is done on an odd address.

For registers r0 to r5 a byte auto-increment or decrement address mode will change the register by one, and word auto-increment or decrement address modes by two.

For register r6, the stack pointer, also a byte auto-increment or decrement address mode will change the stack pointer by two to ensure that a word access is always possible.

wfjm
  • 1,528
  • 10
  • 12