求助汇编语言编写分段函数
2个回答
展开全部
;1 整数形式
; integer number
dseg segment
x dw -1 ;
fx db ?
msg db 'F(x) = $'
dseg ends
cseg segment
assume cs:cseg, ds:dseg
start:
mov ax, dseg
mov ds, ax
mov ax, x ;
call functionX
lea dx, msg
mov ah,9
int 21h
mov ah,0eh
mov al, fx
cmp al, 0
jge m0
mov al, '-'
int 10h
mov al, fx
neg al
m0:
add al, 30H ; //convert to ASCII
int 10h ;
mov ah,4ch
int 21h ; exit to dos
functionX proc near
cmp ax, 1
jGE $1 ;>=1
cmp ax, -1
jle $2 ;<=-1
mov fx, 0 ; -1<x<1
jmp $0
$1:
mov fx, 1
jmp $0
$2:
mov fx,-1
$0:
ret
functionX endp
cseg ends
end start
;2,写完上面程序后才发现,题目要求的应该是浮点数
;a2.asm support float number
.286
dseg segment
x dd 1.0 ;
fx db ?
f1 dd 1.0
fn1 dd -1.0
msg db 'F(x) = $'
dseg ends
cseg segment
assume cs:cseg, ds:dseg
start:
finit
mov ax, dseg
mov ds, ax
call functionX
lea dx, msg
mov ah,9
int 21h
mov ah,0eh
mov al, fx
cmp al, 0
jge m0
mov al, '-'
int 10h
mov al, fx
neg al
m0:
add al, 30H ; //convert to ASCII
int 10h ;
mov ah,4ch
int 21h ; exit to dos
functionX proc near
fld x
fcom f1
fstsw ax
sahf
jaE $1 ;>=1
fcom fn1
fstsw ax
sahf
jbe $2 ;<=-1
mov fx, 0 ; -1<x<1
jmp $0
$1:
mov fx, 1
jmp $0
$2:
mov fx,-1
$0:
ret
functionX endp
cseg ends
end start
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询