汇编语言是否有非处理器特定的指令?
Assembly language are there non-processor-specific instructions?
我刚开始编程汇编,有些地方我不明白。我知道大多数指令都是特定于处理器的,因此我正在使用 PIC 处理器数据表中的指令编写汇编程序。但是当我看这个示例程序时,我从数据表中重新调整了大部分指令,但其中一些没有提到。
我说的是 list, #include, equ, ORG
和 END
命令。我有点明白他们的所作所为,但我不明白他们从哪里来。这是非处理器特定指令还是它们不称为指令?我在哪里可以找到有关它们的文档。
这是示例代码。
;***********************************************************
; 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 来说不是这样),但对于汇编程序来说,文档通常很薄弱。您的体验可能会有所不同。
我刚开始编程汇编,有些地方我不明白。我知道大多数指令都是特定于处理器的,因此我正在使用 PIC 处理器数据表中的指令编写汇编程序。但是当我看这个示例程序时,我从数据表中重新调整了大部分指令,但其中一些没有提到。
我说的是 list, #include, equ, ORG
和 END
命令。我有点明白他们的所作所为,但我不明白他们从哪里来。这是非处理器特定指令还是它们不称为指令?我在哪里可以找到有关它们的文档。
这是示例代码。
;***********************************************************
; 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 来说不是这样),但对于汇编程序来说,文档通常很薄弱。您的体验可能会有所不同。