prog12.asm

来自「包括了各种常用的8051单片机的程序」· 汇编 代码 · 共 75 行

ASM
75
字号
;  PROG12 - Stack Arithmetic Operations
;
;  This Application uses the Simulator to Demonstrate how high
;   Level Language ("C") statements can be implemented in an 8051.
;
;  Note, that comments starting with ";;" are "C" Source Code with the
;   8051 Assembler Source Following.  With this virtual HLL, I am assuming
;   a word size of eight bits.
;
;  This program will run in the UMPS simulator for a DS80C320.
;
;  Myke Predko
;  98.02.12
;
;  Hardware Notes:
;   This program is only meant to run on the Simulator

;  Variable Declarations
;  These declarations are modelled on the "C" Variable Declarations
;;int i, j;                     //  Define some 8 Bit Counters
;;char Output;                  //  Output Character
i EQU 0                         ;  Define R0 as the Counter "i"
j EQU 1                         ;   NOTE: Defines are to Memory Locations, NOT
                                ;   as Bank Registers

Temp EQU 03Fh                   ;  Have a Temporary Register for intermediate
                                ;   Values

Output EQU 030h                 ;  Location for Saving Data

;  Mainline
 org 0                          ;  Execution Starts Here

;;  i = 4 - 3

  mov    i,#1                   ;  Initialize "i" (This was optimized)

;;  j = i + 7

  mov    A,#7                   ;  First, Load the Second Value (which is
  push   ACC                    ;   Added to "i") - Note that "ACC" is being
                                ;   pushed and not "A".
  push   i                      ;  Add the Second value for the assignment to
                                ;   the Stack.
  pop    ACC                    ;  Get the First Value to operate on
  pop    Temp                   ;  Get the Second Value to operate on and put
                                ;   in a variable that can access "ACC"
  add    A,Temp                 ;  A = A - Temp
                                ;    = i + 7
  push   ACC                    ;  Save the Result for the Next Operation
  pop    j                      ;  Retrieve Result and Store in the Destination

;;  Output = ( i * j ) + 'A';   //  Now, Have a Compound Operation

  mov    A,#'A'                 ;  Put the Character Value onto the Stack
  push   ACC

  push   j                      ;  Store the Parameters for the Operations
  push   i

  pop    ACC                    ;  Get the Numbers to Multiply
  pop    B

  mul    AB                     ;  Perform the Multiplication Operation

  pop    Temp

  add    A,Temp                 ;  Add ASCII 'A' to the Multiplication Result

  mov    Output,A               ;  Store the Result (Optimized)


Loop:                           ;  Loop Here Forever when Finished
  ajmp   Loop

⌨️ 快捷键说明

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