汇编语言有非处理器特定的指令吗?

标签 assembly pic

我刚刚开始编程汇编,有一些我不明白的地方。我知道大多数指令都是特定于处理器的,因此我正在使用 PIC 处理器数据表中的指令编写汇编程序。但是,当我查看这个示例程序时,我重新认识了数据表中的大多数指令,但其中有几个指令没有提及。

我正在讨论 list、#include、equ、ORGEND 命令。我有点明白他们在做什么,但我不明白他们从哪里来。这是非处理器特定的指令还是它们不称为指令?在哪里可以找到有关它们的一些文档。

这是示例代码。

;***********************************************************
; 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

最佳答案

汇编语言是一种与其他编程语言一样的编程语言,只是另一种编程语言。但是,与 C 或 C++ 或类似语言不同,该语言是由汇编程序定义的,读取它的程序不是由某些标准机构定义的。因此,即使对于特定目标的特定指令集,也可以有不同的汇编语言。

我不是在谈论 AT&T 与 Intel,所有语法都是语言的一部分。正如您所显示的,大多数汇编语言程序都是代表机器指令的助记符和操作数,但正如您所询问的,有些百分比是标签和指令。就像 C 中的 #include、#define、#typedef、void、unsigned 等。您会发现同一目标的汇编程序之间的最大差异在于指令中,而不是表示指令的行中。有些有:

.section .text

其他:

SECTION TEXT

例如。

对于汇编程序来说,最重要的是获得正确的机器代码,如果他们想要编写一种汇编语言,而不是:

mov r0,r1
add r2,r2,r1

他们期望:

bob apple,orange
joe banana,banana,orange

那就这样吧:它们可能不会获得很多用户,并不意味着它不能生成正确的机器代码。

为此,正如您所评论的,每个指令集架构都是不同的,x86 与arm 完全不兼容,arm 与pic 完全不兼容。因此,汇编语言自然会有所不同,有时您会看到 mov 和 cmp 是相同的助记符,但寄存器等的既定名称有所不同。

因此,正如 Jester 在上面的评论中回答的那样,您需要查阅汇编程序(如您正在使用的特定程序中)文档。遗憾的是,如今(例如 TASM 并非如此),文档对于汇编程序来说通常很薄弱。您的体验可能会有所不同。

关于汇编语言有非处理器特定的指令吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59034519/

相关文章:

组装拼图-二元炸弹

assembly - 查询汇编语言中堆栈指针的使用

c - 从 5v 到 3.3v 的电压电平转换

c - printf 并且在汇编代码中不显示

linux - x86-64 架构上的 gnu 汇编 RET 指令失败

正在编译 GCC NOP

c - PIC18 变量声明和初始化在硬件中失败

microcontroller - PIC18F1220 尝试刷新几个引脚但无法

c - 如何将数字 PIC 端口读入单个变量?

c - 试图了解 Microchip PIC16LF15344 I2C 外围引脚选择