REAL4 숫자는 DWORD와 같이 32 비트 뭉치지만 다른 방식으로 해석됩니다. 특수 MASM 옵션이 필요하지 않고 REAL4를 확인하는 경우 MASM 유형 DWORD resp를 사용할 수도 있습니다. SDWORD 또는 공통 어셈블러 유형 DD.
대부분의 외부 함수의 경우 REAL4 숫자 (단 정밀도 부동 소수점 형식)를 REAL8 숫자 (배정 밀도 부동 소수점 형식)로 변환해야합니다. 가장 쉬운 방법은 싱글을 FPU에로드하고 이중으로 저장하는 것입니다.
콘솔의 입력 내용이 문자열로 저장됩니다. 이 문자열을 원하는 형식으로 변환해야합니다.
하자 최초의 출력 REAL4 번호의 배열 :
INCLUDE \masm32\include\masm32rt.inc
.DATA
result REAL8 0.0
array REAL4 -1.0, 1.2, 2.3, 3.4, 4.567, 0.0
SDWORD -1 ; End of array -> NaN
.CODE
main PROC
xor ebx, ebx
@@:
mov eax, DWORD PTR array[ebx] ; "DWORD PTR" = "REAL4 PTR"
cmp eax, -1 ; NaN = end of array?
je @F ; Yes -> Jump to the next @@
fld DWORD PTR array[ebx] ; Load a single into FPU ...
fstp QWORD PTR result ; ... and store it as double
printf("%f\n",result) ; MASM32 macro that acts like the C function
add ebx, 4 ; REAL4 has 4 bytes
jmp @B ; Jump to the previous @@
@@:
exit 0
main ENDP
END main
지금 입력 숫자의 몇하자 그들을 인쇄 할 수 있습니다. 16 개의 변수가 있습니다. 프로그램이 제한을 검사하지 않습니다. 숫자없이 숫자 만 입력하면 입력을 종료합니다.
INCLUDE \masm32\include\masm32rt.inc
INCLUDE \masm32\macros\macros.asm
.DATA
result REAL8 0.0
lpstring DWORD 0
array REAL4 16 DUP (0.0)
SDWORD -1 ; End of array -> NaN
.CODE
main PROC
xor ebx, ebx
@@:
mov esi, input("Enter number here ",62," ") ; Input string ... STRING!
cmp BYTE PTR [esi], 0; ; Nothing inputted?
je @F ; Yes -> jump forward to the next @@
push ebx ; StrToFloat changes EBX! So it is to save
INVOKE StrToFloat, esi, ADDR result ; Convert string to double
pop ebx ; Restore the saved EBX
fld REAL8 PTR result ; Load a double ...
fstp REAL4 PTR array[ebx] ; ... and save it as single
mov eax, -1 ; NaN = end of array
mov DWORD PTR array[ebx+4], eax ; Store the NaN as the next element
add ebx, 4 ; Pointer to the next REAL4 in array
jmp @B ; Jump back to the previous @@
@@:
xor ebx, ebx
@@:
mov eax, DWORD PTR array[ebx] ; "DWORD PTR" = "REAL4 PTR"
cmp eax, -1 ; NaN = end of array?
je @F ; Yes -> Jump to the next @@
fld DWORD PTR array[ebx] ; Load a single into FPU ...
fstp QWORD PTR result ; ... and store it as double
printf("%f\n",result) ; MASM32 macro that acts like the C function
add ebx, 4 ; REAL4 has 4 bytes
jmp @B ; Jump to the previous @@
@@:
exit 0
main ENDP
END main
'print' 명령어가 없습니다. 아무 것도 인쇄하는 함수를 호출해야합니다. 또는 직접 문자열로 변환하는 코드를 작성해야합니다. 'printf'는'double'과 만 작동하므로'cvtss2sd xmm1, array [ebx]' –
을 원할 수 있습니다. @PeterCordes :'print'는 MASM32 패키지에 포함 된 매크로입니다. – rkhb