0
;
; Author:
; Course:
; Student Number:
; Date:
;
; Purpose:      To illustrate how to solve an equation such as:
;               f(x) = 5x + 3 for x = 0 to 9, using 8-bit Multiplication
;               The calculated x in f(x) values will be placed into the X_Values array
;               The calculated f(x) values will be placed into the Results array
;
ARRAY_LEN       equ     10              ; Number of values to calculate (10): x = 0 to 9
FIVE        equ     $5              ; Need two arrays of length ARRAY_LEN
THREE           equ     $3

X
        db  $0,$1,$2,$3,$4,$5,$6,$7,$8,$9     ; - one holds x = 0 to 9
X_End

fx
        db  X-X_End         ; - one holds f(x) results
fx_End


        org            $1020                 ; org as per assignment instructions
X_Values
        ds         ARRAY_LEN           ; Complete this line of code
                                         ; Value of x used in calculation stored here
End_X_Values

        org            $1030        ; org as per assignment instructions

Results
        ds          ARRAY_LEN       ; Complete this line of code
                                     ; Result of f(x) calculation stored here
End_Results

; Expected Results
;        x       x       x      x       x      x      x      x      x      x
;      $1020   $1021   $1022  $1023   $1024  $1025  $1026  $1027  $1028  $1029
;        00      01      02     03      04     05     06     07     08     09

;       f(x)    f(x)     f(x)   f(x)   f(x)    f(x)   f(x)   f(x)  f(x)    f(x)
;      $1030   $1031   $1032  $1033   $1034  $1035  $1036  $1037  $1038  $1039
;        03      08      0d     12      17     1c     21     26     2b     30


        org     $2000
start       lds     #$2000      ; Stack Initialization
begin       ldx     #X          ; Points to the beginning of x array
            ldy     #Results   ; Points to the beginning of X_Values



Loop        ldaa    1,x+                ;Get the X values
                ldab    #FIVE                ;load 5 to b
                staa    fx
        mul a,b                 ;Multiply a to b
                addb    #THREE
                stab    1,y+
            bra     Check               ; Go to Check block for looping
        
Check       cpx    #X_End
            bne     Loop

        swi
            end

HSC12 汇编程序 - 解决 f(x) = 5x+3,我能够将方程的结果正确地放入内存中,价格为 1030 美元。我无法将 x 数组值 0-9 放入 x_values 的内存位置。另外我如何使用 fx 数组来保存结果并将它们放在结果的内存位置?任何帮助将非常感激 !很难找到有关此主题的资源。谢谢你。

4

0 回答 0