アセンブリ言語を使用して単純なコサイン(x)波をプロットする必要があります。私は教授の指示に従ってプロジェクトのすべてのステップを完了しましたが、プログラムを正しく印刷することができません。これは、ここでNASM x86アセンブリを使用して余弦波をプロットする
*****
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
** **
** **
が私のコードです...、私が得る出力され
linux2[14]% cat plot4.out
*****************************************
しかし、それはする必要があります。いかなる援助も感謝します。
SECTION .data ; Data section, initialized variables
nrow: dq 21 ; 21 rows
ncol: dq 41 ; 41 columns
fmtc: db "%c", 0 ; print one character at a time
fmtend: db 10, 0 ; end a line
star: db '*' ; one character '*'
fmtendLen: equ $-fmtend
pStar: db "*"
starLen: equ $-pStar
pSpace: db " "
spaceLen: equ $-pSpace
len: equ $-star
spc: db ' '
af: dq 1.0, 0.0, -0.5 ; coefficients of polynomial, a_0 first
dq 0.0, 0.041667, 0.0, -0.001389, 0.0, 0.000025
XF: dq 0.0 ; computed
Y: dq 0.0 ; computed
N: dq 8 ; power of polynomial
X0: dq -3.14159 ; start XF
DX0: dq 0.15708 ; increment for XF ncol-1 times
one: dq 1.0
ten: dq 10.0
none: dq -1.0
nten: dq -10.0
twenty: dq 20.0
zero: dq 0.0
newline: db 10
section .bss
a2: resb 21*41 ; two dimensional array of bytes
i: resq 1 ; row subscript
j: resq 1 ; col subscript
k: resq 1
SECTION .text ; Code section.
global _start ; the standard gcc entry point
_start: ; the program label for the entry point
;;; clear a2 to space
mov rax,0 ; i=0
mov [i],rax
loopi:
mov rax,[i]
mov rbx,0 ; j=0
mov [j],rbx
loopj:
mov rax,[i]
mov rbx,[j]
imul rax,[ncol] ; i*ncol
add rax, rbx ; i*ncol + j
mov dl, [spc] ; need just character, byte
mov [a2+rax],dl ; store space
mov rbx,[j]
inc rbx ; j++
mov [j],rbx
cmp rbx,[ncol] ; j<ncol
jne loopj
mov rax,[i]
inc rax ; i++
mov [i],rax
cmp rax,[nrow] ; i<ncol
jne loopi
;;; end clear a2 to space
mov rax, 0 ;i = 0
mov [i], rax
mov rbx, 0 ;j = 0
mov [j], rbx
cos:
mov rcx,[N] ; loop iteration count initialization, n
fld qword [af+8*rcx] ; accumulate value here, get coefficient a_
h5loop:
fmul qword [XF] ; * XF
fadd qword [af+8*rcx-8] ; + aa_n-i
loop h5loop ; decrement rcx, jump on non zero
fstp qword [Y] ; store Y
;;; ; ; compute k
fld qword [Y]
fadd qword [one]
fmul qword [ten]
fmul qword [none]
fadd qword [twenty]
fistp qword [k]
;;; ; ; ; ; rax gets k * ncol + j
mov rax, [k]
mov rbx, [j]
imul rax, [ncol]
add rax, rbx
;;; ; ; put "*" in dl, then dl into [a2+rax]
mov dl, [star]
mov [a2+rax], dl
;;; ; ; XF = XF + DX0
fld qword [XF]
fadd qword [DX0]
fistp qword [XF]
mov rbx, [j]
inc rbx ; j++
mov [j], rbx
cmp rbx,[ncol] ; j<ncol
jne cos
;;; print
mov rax,0 ; i=0
mov [i],rax
ploopi:
mov rax,[i]
mov rbx,0 ; j=0
mov [j],rbx
ploopj:
mov rax,[i]
mov rbx,[j]
mov dl, [spc]
imul rax,[ncol]
add rax, rbx
mov rax, [i] ; a2+i*ncol+j is byte
imul rax, [ncol]
add rax, [j]
add rax, a2
mov rsi, rax ; address of character to print
mov rax, 1 ; system call 1 is write
mov rdi, 1 ; file handle 1 is stdout
mov rdx, 1 ; number of bytes
syscall ; invoke operating system to do the write
;;; print here
mov rbx,[j]
inc rbx ; j++
mov [j],rbx
cmp rbx,[ncol] ; j<ncol
jne ploopj
mov rdi, fmtend
mov rax, 1
mov rdi, 1 ; file handle 1 is stdout
mov rsi, newline ; address of string to output
mov rdx, 1 ; number of bytes
syscall
;;; print here
mov rax,[i]
inc rax ; i++
mov [i],rax
cmp rax,[nrow] ; i<ncol
jne ploopi
;;; print a2
mov eax, 60 ; system call 60 is exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
単一のステップにあなたのプログラムをデバッガを使用して、それがうまくいかない場所を確認。 – Jester
これは本当に愚かなことかもしれません...しかし、あなたはそれを行う方法を教えてください。 – marz123
を使用すると、デバッガに精通していない場合、それは'ddd'のようなGUIを使って何かをつかむのが最も簡単かもしれません。トン。私はあなた自身がそれを見つけることができると信じています、ここでのコメントでデバッガを使う方法を教えてはいけません。 – Jester