Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the microprocessor simulator, open the program 99Step.asm. Step through it

ID: 640217 • Letter: U

Question

Using the microprocessor simulator, open the program 99Step.asm. Step through its execution to understand its current operation. Explain the operation of the program in detail. Using bit operations, write a program to spin the stepper motor using a) full stepping and b) half stepping. Simulate/Run the full stepping and half stepping individually. To run the code remember to add delays for each activation of the magnets. (may not be needed for stepping through the code) Validate your design for the expected results and troubleshoot the code if any errors. Explain the steps you took to validate your design. Explain any errors you had and how you determined the errors and fixed them. Take a screenshot of the modified assembly code for full stepping and half stepping mode. Add some screenshots for step by step execution of the code (show the motor in several different positions as the program is stepped through).

Explanation / Answer

Writing a Program

To write and run a program using the simulator, select the text editor by pressing

{bmc bm3.WMF}

Alt+D

and type in the program. It is best to get small parts of the program working rather than typing it all in at once. To get started, look at the tutorial example programs. Base your first programs on these. You can switch backwards and forwards between help and your program by pressing Alt+Tab

Running a Program

To run a program, you can step through it one command at a time by pressing

{bmc bm4.WMF}

Alt+P

repeatedly. You can run a program without single stepping by pressing

{bmc bm5.WMF}

Alt+R or F9

Assembly Code

The code you type is called assembly code. You can translate the assembly code into machine code understood by the CPUCPU by pressing

{bmc bm6.WMF}

Alt+A

If necessary, this is done automatically when you press Run or Step.

Viewing Machine Code

The machine code stored in RAM can be viewed in three modes by selecting the Tab of your choice.

The Hexadecimal_AX.K4 display corresponds exactly to the binary executed by the CPU. The ASCII2838Z_ display is convenient if your program is processing text. The text is readable but the machine codes are not. The source code display shows how the assembly code commands are placed in memory. In normal use, these displays work quite well. It is possible to deliberately confuse the display.

For example              MOV AL,15           translates into            D0 00 15.

Instead of typing in the MOV command as above try this.

              DB   D0

              DB   00

              DB   15

The same machine codes will be generated. The program will work in the same way. The displays will no longer recognise that it was a MOV command.

JMPJMP     Start   ; Jump past table of interrupt vectors

        DBDB      50       ; Vector at 02 pointing to address 50

Start:

        STISTI              ; Set I flag. Enable hardware interrupts

        MOVMOV     AL,11    ;

Rep:

        OUTOUT     05       ; Stepper motor

        RORROR     AL       ; Rotate bits in AL right

        JMPJMP     Rep

        JMPJMP     Start

; --------------------------------------------------------------

        ORGORG     50

        PUSHPUSH    al       ; Save AL onto the stack.

        PUSHPUSH    bl       ; Save BL onto the stack.

        PUSHFPUSHF            ; Save flags onto the stack.

        JMPJMP     PastData

        DBDB      84       ; Red       Green

        DBDB      c8       ; Red+Amber Amber

        DBDB      30       ; Green           Red

        DBDB      58       ; Amber           Red+Amber

        DBDB      57       ; Used to track progress through table

PastData:

        MOVMOV     BL,[5B] ; BL now points to the data table

        MOVMOV     AL,[BL] ; Data from table goes into AL

        OUTOUT     01       ; Send AL data to traffic lights

        CMPCMP     AL,58    ; Last entry in the table

        JZJZ      Reset    ; If last entry then reset pointer

        INCINC     BL       ; BL points to next table entry

        MOVMOV     [5B],BL ; Save pointer in RAM

        JMPJMP     Stop

Reset:

        MOVMOV     BL,57    ; Pointer to data table start address

        MOVMOV     [5B],BL ; Save pointer into RAM location 54

Stop:

        POPFPOPF             ; Restore flags to their previous value

        POPPOP     bl       ; Restore BL to its previous value

        POPPOP     al       ; Restore AL to its previous value

        IRETIRET

; --------------------------------------------------------------

        ENDEND