나는 코 프로세서를 사용하여 사인을 계산하는 방법을 예제를 찾고있다. 내가 찾은 기능 :어셈블리에서 사인 예를 계산합니다. nasm 16 dos
CalcSin
fld long [angle] ; st(0) = angle
fsin ; st(0) = sin(angle) (angle is in radians)
fstp long [SinX] ; SinX = sin(angle)
내가 사인 그리려는 내가 bx
에 ax
에서 Y와 X에 필요합니다. 루프를 만들 것이기 때문에 X는 문제가되지 않지만 Y는 문제가 있습니다. X는 예제 0에서 350까지입니다 (예 : 픽셀). 예를 들어 죄 (30도)가 1/2 인 경우 픽셀을 계산하고 Y를 갖는 방법. 좋은 좌표로 결과를 둥글게 만드는 방법은 무엇입니까?
편집 : 가 미안 해요,하지만 난 당신의 코드를 실행할 때 나는 그것이 나에게 더 부비동을 보여줍니다 만, 2 개 라인. 나는 당신이 제대로, 당신이 어떤 변환 및 크기 조정을하지 않고 사인파를 그리려 이해한다면 지금
segment .data
segment .code
..start:
mov ax, 13h
int 10h ; switch to 320x200 mode
mov ax, 0a000h ; The offset to video memory
mov es, ax ; We load it to ES through AX,
; because immediate operation
; is not allowed on ES
;;;;;;;;;;;;;;;;;;;;;;
DrawWave:
mov ebx, y ; EBX = &y
mov ecx, 0
; let st(1) = 2*PI/640
fldpi ; st(0) = PI
fidiv dword [step] ; st(0)/160 = 0.009817...
fldz ; st(0) = 0.0, st(1) = 0.00045...
.loop:
fld st0 ; duplicate the x on the top
fsin ; st(0) = sin x
fimul dword [imgHeight] ; st(0) = y*240
fiadd dword [imgHeight] ; eliminate negative coordinate by translating the wave vertically
fistp dword [y] ; store y to ´y´
fadd st0, st1 ; add the step value to x, doing the step
;draw pixel at [*EAX:ECX]
push ax
push bx
push cx
call DrawPixel
pop cx
pop bx
pop ax
inc ecx
cmp ecx, 320 ; perform 640 steps to draw a single sine wave
jl .loop
fstp st0 ;clean up
fstp st0 ;clean up
ret
;;;;;;;;;;;;;;;;;;;;;;;;;
xor ah, ah
int 16h ; keyboard (wait for key)
mov ax, 3
int 10h ; go to text mode
mov ax, 4c00h
int 21h ; return to DOS, exit code 0
;;;;;;;;;;;;;;;;;;;;;
; EBX = in &CoordY
; ECX = CoordX
;DrawPixel:
; draw a pixel at [*EBX:ECX]
; ret
DrawPixel:
push dx ; mul changes dx too
mov ax, cx ; ax is X coord copy from cx
mov cx, 320
mul cx ; multiply Y (ax) by 320 (one row)
add ax, bx ; and add X (bx) (result= dx:ax)
mov di, ax
pop dx
mov dl, 4
mov [es:di], dl ; store color/pixel
ret
;CONSTANTS:
step: dw 160 ; 2/320 = 160
imgWidth: dw 320 ; 320px
imgHeight: dw 200/2 ; 200px on half, because Y also gets negative
;VARIABLES:
x: dw 0 ; a tmp place to save X
y: dw 0 ; a tmp place to save Y
'나는 사인을 그려보고 싶다'- 무엇을 의미합니까? 사인파? – user35443
예. 나중에 사인파 애니메이션이 될 것입니다. 하지만 사인파에서 시작하고 싶습니다 – kkkkk
저는 제 대답을 만들고 있습니다. – user35443