简体   繁体   中英

Assembly language are there non-processor-specific instructions?

I just started programming assembly and there is something I don't understand. I know most instructions are processor specific and so I'm writing my assembly program using the instructions from the datasheet of my PIC processor. But when I look at this example program I reconize most instructions from the datasheet but a couple of them are not mensioned.

I'm talking about the list, #include, equ, ORG and END command. I kind of get what they do but I don't understand where they come from. Are this non-processor-specific instructions or are they not called instructions and where do I find some documentation about them.

Here is the example code.

;***********************************************************
; File Header
;***********************************************************

list p=18F25k50, r=hex, n=0
#include <p18f25k50.inc>

X1 equ  0x00
Y1 equ  0x01
C1 equ  0x03
C2 equ  0x04
C3 equ  0x05

;***********************************************************
; Reset Vector
;***********************************************************

    ;ORG   0x000  ; DEBUG Reset Vector
    ORG    0x1000  ; LOAD
         ; When debugging:0x000; when loading: 0x1000
    GOTO    START


;***********************************************************
; Interrupt Vector
;***********************************************************



    ;ORG    0x008
    ORG     0x1008  ; Interrupt Vector  HIGH priority
    GOTO    inter_high  ; When debugging:0x008; when loading: 0x1008
    ;ORG    0x018
    ORG     0x1018  ; Interrupt Vector  HIGH priority
    GOTO    inter_low   ; When debugging:0x018; when loading: 0x1018



;***********************************************************
; Program Code Starts Here
;***********************************************************

    ORG     0x1020      ; When debugging:0x020; when loading: 0x1020
    ;ORG    0x020
START
    movlw   0x80        ; load value 0x80 in work register
    movwf   OSCTUNE     
    movlw   0x70        ; load value 0x70 in work register
    movwf   OSCCON      
    movlw   0x10        ; load value 0x10 to work register
    movwf   OSCCON2     
    clrf    PORTA       ; Initialize PORTA by clearing output data latches
    movlw   0x00        ; Value used to initialize data direction
    movwf   TRISA       ; Set PORTA as output
    movlw   0x00        ; Configure A/D for digital inputs 0000 1111
    movwf   ANSELA      ;
    movlw   0x00        ; Configure comparators for digital input
    movwf   CM1CON0
    clrf    PORTB       ; Initialize PORTB by clearing output data latches
    movlw   0x00        ; Value used to initialize data direction
    movwf   TRISB       ; Set PORTB as output
    clrf    PORTC       ; Initialize PORTC by clearing output data latches
    movlw   0x01        ; Value used to initialize data direction
    movwf   TRISC       ; Set RC0 as input

    bcf     UCON,3      ; to be sure to disable USB module    
    bsf     UCFG,3      ; disable internal USB transceiver

main
    clrf    X1          ; clear registers
    clrf    Y1
    movlw   0x01        ; move 0x01 to Register X1
    movwf   X1

ifstart 
    btfss   PORTC,0          ; check RC0, if it?s equal ?1? continue
    goto    shifter          ; else go back
    goto    delay        ; wait so proces is visable for humans
    postdelay
    goto    ifstart

shifter                  ; Linear Feedback Shift Register
    movf    X1,0             ; move X1 into W register
    movff   X1,Y1            ; move X1 value to Y1
    rlcf    Y1               ; shift 1bit to left
    xorwf   Y1,1             ; xor W with Y1, store the result in Y1
    btfsc   Y1,3             ; test if Y1bit 3 is 0,skip to the State2
    goto    state1
    goto    state2

state1
    rlcf    X1                ; shift 1 bit to left
    bsf     X1,0              ; set bit 0 to 1
    movf    X1,0              ; move X1 to PORTB
    movwf   PORTA
    goto    ifstart

state2
    rlcf    X1
    bcf     X1,0
    movf    X1,0
    movwf   PORTA
    goto    ifstart

inter_high
    nop
    RETFIE
inter_low
    nop
    retfie

delay
    incfsz  C1          ; wait 256 (P = 6.4us)
    goto    delay       ; go back
    incfsz  C2          ; wait 256*256 = 65536 (P = 1.6ms)
    goto    delay       ; go back
    incf    C3          ; wait 256*256*64 = 10223616 (P = 0.255s)
    btfss   C3, 5 
    goto    delay       ; go back
    goto    postdelay       ; delay is over 
END

Assembly language is a programming language like any other, just another programming language. But, unlike C or C++ or something like that the language is defined by the assembler, the program that reads it not by some standards body. So even for a specific instruction set for a particular target there can be and are different assembly languages.

I am not talking about AT&T vs Intel, all of the syntax is part of the language. Most of assembly language programs as you have shown are mnemonics and operands that represent machine instructions, but some percentage is labels and directives as you are asking about. Like #include, #define, #typedef, void, unsigned, etc in C. Where you find most differences between assemblers for the same target is in the directives more than the lines that represent instructions. Some have:

.section .text

others:

SECTION TEXT

for example.

What is most important for an assembler is to get the machine code right if they want to write an assembly language that instead of:

mov r0,r1
add r2,r2,r1

they expect:

bob apple,orange
joe banana,banana,orange

then so be it: they might not get many users, doesn't mean it can't produce proper machine code.

And to that end as you have commented, each instruction set architecture is different x86 is completely incompatible with arm which is completely incompatible with pic. So naturally the assembly languages will vary, sometimes you see mov, and, cmp, being the same mnemonic, but the established names for the registers and such vary.

So as answered in the comments above by Jester, you need to consult the assembler (as in the specific program you are using) documentation. Saying that though sadly these days (was not like this for TASM for example) the documentation is often weak for assemblers. Your experience may vary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM