movlw  0x05
movwf  0x23
movlw  B´00111000´
movwf  STATUS
bcf    TRISA,0
bcf    TRISA,1
bcf    STATUS,5
bsf    PORTA,1
movlw  0x07
movwf  0x25
movlw  0xFF
andwf  0x25,1
nop
movlw  0x0F
movwf  0x27
clrw
iorwf

Dani AI

Generated

Brief, register-level walkthrough (with corrections to earlier replies) for and follow-ups by and .

movlw 0x05 / movwf 0x23

  • File 0x23 receives 0x05; W remains 0x05 after movwf.

movlw B'00111000' / movwf STATUS

  • STATUS becomes 0x38 (binary 00111000). On classic PIC16 devices bits 6:5 are the bank-select bits (RP1:RP0), so writing 0x38 sets RP0 and also writes bits 4 and 3 (TO, PD) to 1. Because the bank bits change, the very next bit/port accesses address different banked registers unless the code explicitly returns the bank.

bcf TRISA,0 / bcf TRISA,1

  • Clearing a TRIS bit makes that pin an output (TRIS bit = 0 -> output). Both TRISA,0 and TRISA,1 are cleared here, so both RA0 and RA1 become outputs (this corrects 's comment that RA1 was being made input).

bcf STATUS,5 / bsf PORTA,1

  • bcf STATUS,5 clears RP0 and returns to the previous bank (bank 0). Then PORTA,1 is set high in that bank.

movlw 0x07 / movwf 0x25 ; movlw 0xFF / andwf 0x25,1

  • 0x25 is set to 0x07. ANDing it with W=0xFF stores 0x07 back to 0x25 (no change). andwf with destination=1 stores the result in the file register.

Remaining lines and errors

  • movwf 0x27 sets file 0x27 = 0x0F. The sequence clrw then iorwf is incomplete: iorwf needs operands and with W cleared it would be a no-op anyway. The binary literal in the original post uses typographic quotes (B´...´) which will fail assembly.

Practical notes

  • Overwriting STATUS with movwf is a fragile bank-switch technique because it also clobbers TO/PD (and possibly other writable bits). Prefer symbolic banking (e.g. the assembler banksel pseudo-op) or explicit bsf/bcf of the bank bits. Example pattern:
banksel TRISA
bcf TRISA,0
bcf TRISA,1
banksel PORTA
bsf PORTA,1
  • Use the simulator and the Special Function Register window (as suggested) to single-step and watch W, STATUS, TRIS/PORT and the file-address map for the specific PIC device; the numeric file addresses (0x23, 0x25, 0x27) must be checked against the device datasheet or header file to know the named SFRs.

Recommended Answers

All 3 Replies

Suspect you're usig a PIC microcontroller.
More explanation would help.

Nothing special to comment for the code except that it is setting port RA0 as ouput in line #5, port RA1 as input in line #6. Lines #4 and line #7 make no sense because status register is destination for arithmetic results, so to read and not to write into it. Lines #11 and #12 do nothing: an andoperation between register 'w' (=0xFF) and register 25 leaves register 25 as it was.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.