⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 destest.asm

📁 microchip网站上找的pic18F458单片机的示例代码
💻 ASM
字号:
;-----------------------------------------------------------------------------
; DES test code
; Copyright 1994, 1996, 1997 Eric L. Smith
;
; $Header$
;-----------------------------------------------------------------------------

	processor	16c84
	include		"p16c84.inc"
        __CONFIG        _CP_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC
        radix           dec
        errorlevel      -224
        errorlevel      -305


;-----------------------------------------------------------------------------
; memory map
;-----------------------------------------------------------------------------

rambase	equ	0x0c
rombase	equ	0x000

;sboxbase equ    0x300


;-----------------------------------------------------------------------------
; RAM definitions
;-----------------------------------------------------------------------------

        cblock  rambase

tdata:  8
temp
index
        endc


;-----------------------------------------------------------------------------
; vectors
;-----------------------------------------------------------------------------

	org	rombase

	goto	reset
	nop
	nop
	nop
	goto	reset


;-----------------------------------------------------------------------------
; test vectors
;-----------------------------------------------------------------------------

testvec:
        clrf    PCLATH
        addlw   PCL
tabbeg: dt      0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x80 ; key
        dt      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; plaintext
        dt      0x9c,0xc6,0x2d,0xf4,0x3b,0x6e,0xed,0x74 ; ciphertext

        dt      0x80,0x01,0x01,0x01,0x01,0x01,0x01,0x01 ; key
        dt      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; plaintext
        dt      0xa3,0x80,0xe0,0x2a,0x6b,0xe5,0x46,0x96 ; ciphertext

        dt      0x08,0x19,0x2a,0x3b,0x4c,0x5d,0x6e,0x7f ; key
        dt      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; plaintext
        dt      0x25,0xdd,0xac,0x3e,0x96,0x17,0x64,0x67 ; ciphertext

        dt      0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef ; key
        dt      "Now is t"                              ; plaintext
        dt      0x3f,0xa4,0x0e,0x8a,0x98,0x4d,0x48,0x15 ; ciphertext
tabend:

        if      (tabbeg>>8)!=(tabend>>8)
        error   "test vectors must reside within a single page"
        endif

maxindex equ tabend-tabbeg


;-----------------------------------------------------------------------------
; copies 8 bytes of data from the testvec array starting at index
; into RAM pointed to by FSR.
;
; on exit, index is increased by 8, but FSR is unchanged
;-----------------------------------------------------------------------------

getdata:
        movlw   tabbeg>>8
        movwf   PCLATH
        movlw   8
        movwf   temp
gd0:    movf    index,W
        call    testvec
        movwf   INDF
        incf    index
        incf    FSR
        decfsz  temp
        goto    gd0
        movlw   -8
        addwf   FSR
        return


compare:
        movlw   tabbeg>>8
        movwf   PCLATH
        movlw   8
        movwf   temp
cmp0:   movf    index,W
        call    testvec
        xorwf   INDF,W
        btfss   STATUS,Z
        goto    cmpne
        incf    index
        incf    FSR
        decfsz  temp
        goto    cmp0
        movlw   -8
        addwf   FSR
        bsf     STATUS,Z
        return


cmpne:  movf    temp,W
        addwf   index
        addwf   FSR
        movlw   -8
        addwf   FSR
        bcf     STATUS,Z
        return





;-----------------------------------------------------------------------------
; initialization code
;-----------------------------------------------------------------------------

reset:
        movlw   0xff            ; all port pins are inputs (or inactive
        tris    PORTA           ; open-drain outputs)
        tris    PORTB
        clrf    PORTA
        clrf    PORTB


;-----------------------------------------------------------------------------
; main loop
;-----------------------------------------------------------------------------

main:   movlw   0
        movwf   index
loop:   movlw   tdata
        movwf   FSR
        call    getdata
        call    setkey
        call    getdata
        call    des
        call    compare
        movf    index,W
        xorlw   maxindex
        btfss   STATUS,Z
        goto    loop
        goto    main


;-----------------------------------------------------------------------------
; actual DES
;-----------------------------------------------------------------------------

des:
        movlw   sboxbase>>8     ; set up to call s-boxes
        movwf   PCLATH
	call	ip
	call	descore
        goto    ipinv


desinv:
        movlw   sboxbase>>8     ; set up to call s-boxes
        movwf   PCLATH
	call	ip
	call	desinvcore
        goto    ipinv


        include "des.inc"

	end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -