SYS_EXIT equ 1
SYS_READ equ 3
SYS_WRITE equ 4
STDIN equ 0
STDOUT equ 1
section .data
msg3 db "Enter the first equation in the form (ax+by=c) :", 0xA,0xD
len3 equ $- msg3
msg1 db "Enter a", 0xA,0xD
len1 equ $- msg1
msg2 db "Enter b", 0xA,0xD
len2 equ $- msg2
msg4 db "Enter c", 0xA,0xD
len4 equ $- msg4
msg5 db "Enter the second equation in the form (px+qy=r) :", 0xA,0xD
len5 equ $- msg5
msg6 db "Enter p", 0xA,0xD
len6 equ $- msg6
msg7 db "Enter q", 0xA,0xD
len7 equ $- msg7
msg8 db "Enter r", 0xA,0xD
len8 equ $- msg8
msg10 db "The value of x is:", 0xA,0xD
len10 equ $- msg10
msg11 db "The value of y is:", 0xA,0xD
len11 equ $- msg11
msg12 db "Infinitely many solutions are possible", 0xA,0xD
len12 equ $- msg12
msg13 db "The value of x can be varied and y can be calculated according to x's value using relation [y=%lf+(%lf)x]", 0xA,0xD
len13 equ $- msg13
msg14 db "No solutions are possible", 0xA,0xD
len14 equ $- msg14
section .bss
a resb 10
b resb 10
c resb 10
p resb 10
q resb 10
r resb 10
x resb 10
y resb 10
temp_res1 resb 10
temp_res2 resb 10
temp_res3 resb 10
temp1 resb 10
temp2 resb 10
temp3 resb 10
temp4 resb 10
temp5 resb 10
temp6 resb 10
temp7 resb 10
temp8 resb 10
temp9 resb 10
temp10 resb 10
temp11 resb 10
temp12 resb 10
temp13 resb 10
temp14 resb 10
temp15 resb 10
temp16 resb 10
temp17 resb 10
temp18 resb 10
temp19 resb 10
temp20 resb 10
temp21 resb 10
temp22 resb 10
temp23 resb 10
temp24 resb 10
temp25 resb 10
temp26 resb 10
temp27 resb 10
temp28 resb 10
temp29 resb 10
temp30 resb 10
temp31 resb 10
temp32 resb 10
temp33 resb 10
temp34 resb 10
temp35 resb 10
temp36 resb 10
temp37 resb 10
temp38 resb 10
temp39 resb 10
temp40 resb 10
temp41 resb 10
temp42 resb 10
section .text
global _start
_start:
mov edx, len3 ; prompts user to enter the values a,b,c
mov ecx, msg3
mov ebx, STDOUT
mov eax, SYS_WRITE
mov edx, len1
mov ecx, msg1
mov ebx, STDOUT
mov eax, SYS_WRITE
mov edx, 10
mov ecx, a
mov ebx, STDIN
mov eax, SYS_READ
mov edx, len2
mov ecx, msg2
mov ebx, STDOUT
mov eax, SYS_WRITE
mov edx, 10
mov ecx, b
mov ebx, STDIN
mov eax, SYS_READ
mov edx, len4
mov ecx, msg4
mov ebx, STDOUT
mov eax, SYS_WRITE
mov edx, 10
mov ecx, c
mov ebx, STDIN
mov eax, SYS_READ
mov edx, len5 ; prompts user to enter the values p,q,r
mov ecx, msg5
mov ebx, STDOUT
mov eax, SYS_WRITE
mov edx, len6
mov ecx, msg6
mov ebx, STDOUT
mov eax, SYS_WRITE
mov edx, 10
mov ecx, p
mov ebx, STDIN
mov eax, SYS_READ
mov edx, len7
mov ecx, msg7
mov ebx, STDOUT
mov eax, SYS_WRITE
mov edx, 10
mov ecx, q
mov ebx, STDIN
mov eax, SYS_READ
mov edx, len8
mov ecx, msg8
mov ebx, STDOUT
mov eax, SYS_WRITE
mov edx, 10
mov ecx, r
mov ebx, STDIN
mov eax, SYS_READ
mov al, [a]
sub al, '0'
mov bl, [q]
sub bl, '0'
mul bl
add al, '0'
mov [temp13], al
mov al, [p]
sub al, '0'
mov bl, [b]
sub bl, '0'
mul bl
add al, '0'
mov [temp14], al
mov eax, [temp13] ; a*q - p*b
sub eax, '0'
mov ebx, [temp14]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp15], eax
mov al, [b]
sub al, '0'
mov bl, [p]
sub bl, '0'
mul bl
add al, '0'
mov [temp16], al
mov al, [q]
sub al, '0'
mov bl, [a]
sub bl, '0'
mul bl
add al, '0'
mov [temp17], al
mov eax, [temp16] ; b*p - q*a
sub eax, '0'
mov ebx, [temp17]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp18], eax
;if(((a*q-p*b)!=0)&&((b*p-q*a)!=0))
mov eax, [temp15]
cmp eax, '0'
setne bh
mov ebx, [temp18]
cmp ebx, '0'
setne ah
and bh, ah
je case_1_stmt
;x = (c*q - r*b)/(a*q - p*b)
case_1_stmt:
mov al, [c]
sub al, '0'
mov bl, [q]
sub bl, '0'
mul bl
add al, '0'
mov [temp1], al
mov al, [r]
sub al, '0'
mov bl, [b]
sub bl, '0'
mul bl
add al, '0'
mov [temp2], al
mov eax, [temp1]
sub eax, '0'
mov ebx, [temp2]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp3], eax
mov al, [a]
sub al, '0'
mov bl, [q]
sub bl, '0'
mul bl
add al, '0'
mov [temp4], al
mov al, [p]
sub al, '0'
mov bl, [b]
sub bl, '0'
mul bl
add al, '0'
mov [temp5], al
mov eax, [temp4]
sub eax, '0'
mov ebx, [temp5]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp6], eax
mov ax, [temp3]
sub ax, '0'
mov bl, [temp6]
sub bl, '0'
div bl
add ax, '0'
mov [x], ax
; y = (c*p - r*a)/(b*p - q*a)
mov al, [c]
sub al, '0'
mov bl, [p]
sub bl, '0'
mul bl
add al, '0'
mov [temp7], al
mov al, [r]
sub al, '0'
mov bl, [a]
sub bl, '0'
mul bl
add al, '0'
mov [temp8], al
mov eax, [temp7]
sub eax, '0'
mov ebx, [temp8]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp9], eax
mov al, [b]
sub al, '0'
mov bl, [p]
sub bl, '0'
mul bl
add al, '0'
mov [temp10], al
mov al, [q]
sub al, '0'
mov bl, [a]
sub bl, '0'
mul bl
add al, '0'
mov [temp11], al
mov eax, [temp10]
sub eax, '0'
mov ebx, [temp11]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp12], eax
mov ax, [temp9]
sub ax, '0'
mov bl, [temp12]
sub bl, '0'
div bl
add ax, '0'
mov [y], ax
;print the value of x
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg10
mov edx, len10
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, x
mov edx, 10
int 0x80
;print the value of y
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg11
mov edx, len11
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, y
mov edx, 10
int 0x80 ; end of case_1_stmt
call exit ; exits program
mov al, [a]
sub al, '0'
mov bl, [q]
sub bl, '0'
mul bl
add al, '0'
mov [temp19], al
mov al, [p]
sub al, '0'
mov bl, [b]
sub bl, '0'
mul bl
add al, '0'
mov [temp20], al
mov eax, [temp19] ; a*q - p*b
sub eax, '0'
mov ebx, [temp20]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp21], eax
mov al, [b]
sub al, '0'
mov bl, [p]
sub bl, '0'
mul bl
add al, '0'
mov [temp22], al
mov al, [q]
sub al, '0'
mov bl, [a]
sub bl, '0'
mul bl
add al, '0'
mov [temp23], al
mov eax, [temp22] ; b*p - q*a
sub eax, '0'
mov ebx, [temp23]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp24], eax
mov al, [c]
sub al, '0'
mov bl, [q]
sub bl, '0'
mul bl
add al, '0'
mov [temp25], al
mov al, [r]
sub al, '0'
mov bl, [b]
sub bl, '0'
mul bl
add al, '0'
mov [temp26], al
mov eax, [temp25] ; c*q - r*b
sub eax, '0'
mov ebx, [temp26]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp27], eax
mov al, [c]
sub al, '0'
mov bl, [p]
sub bl, '0'
mul bl
add al, '0'
mov [temp28], al
mov al, [r]
sub al, '0'
mov bl, [a]
sub bl, '0'
mul bl
add al, '0'
mov [temp29], al
mov eax, [temp28] ; c*p - r*a
sub eax, '0'
mov ebx, [temp29]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp30], eax
;else if(((a*q-p*b)==0)&&((b*p-q*a)==0)&&((c*q-r*b)==0)&&((c*p-r*a)==0))
mov eax, [temp21]
cmp eax, '0'
sete bh
mov ebx, [temp24]
cmp ebx, '0'
sete ah
and bh, ah
mov ecx, [temp27]
cmp ecx, '0'
sete ch
and ch, bh
mov edx, [temp30]
cmp edx, '0'
sete dh
and dh, ch
je case_2_stmt
case_2_stmt:
mov ax, c
sub ax, '0'
mov bl, b
sub ax, '0'
div bl
add ax, '0'
mov [temp_res1], ax ; (c/b)
mov ax, a
sub ax, '0'
mov bl, b
sub ax, '0'
div bl
add ax, '0'
mov [temp_res2], ax
mov dl, [temp_res2]
sub dl, '0'
mov al, 0FFH ; 0FFH = -1
sub al, '0'
imul dl ; (-1*a/b)
add dl, '0'
mov [temp_res3], dl
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg13
mov edx, len13
int 0x80;
mov edx, 10
mov ecx, temp_res1
mov ebx, STDOUT
mov eax, SYS_WRITE
int 0x80;
mov edx, 10
mov ecx, temp_res3
mov ebx, STDOUT
mov eax, SYS_WRITE
call exit ; exits program
mov al, [a]
sub al, '0'
mov bl, [q]
sub bl, '0'
mul bl
add al, '0'
mov [temp31], al
mov al, [p]
sub al, '0'
mov bl, [b]
sub bl, '0'
mul bl
add al, '0'
mov [temp32], al
mov eax, [temp31] ; a*q - p*b
sub eax, '0'
mov ebx, [temp32]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp33], eax
mov al, [b]
sub al, '0'
mov bl, [p]
sub bl, '0'
mul bl
add al, '0'
mov [temp34], al
mov al, [q]
sub al, '0'
mov bl, [a]
sub bl, '0'
mul bl
add al, '0'
mov [temp35], al
mov eax, [temp34] ; b*p - q*a
sub eax, '0'
mov ebx, [temp35]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp36], eax
mov al, [c]
sub al, '0'
mov bl, [q]
sub bl, '0'
mul bl
add al, '0'
mov [temp37], al
mov al, [r]
sub al, '0'
mov bl, [b]
sub bl, '0'
mul bl
add al, '0'
mov [temp38], al
mov eax, [temp37] ; c*q - r*b
sub eax, '0'
mov ebx, [temp38]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp39], eax
mov al, [c]
sub al, '0'
mov bl, [p]
sub bl, '0'
mul bl
add al, '0'
mov [temp40], al
mov al, [r]
sub al, '0'
mov bl, [a]
sub bl, '0'
mul bl
add al, '0'
mov [temp41], al
mov eax, [temp40] ; c*p - r*a
sub eax, '0'
mov ebx, [temp41]
sub eax, '0'
sub eax, ebx
add eax, '0'
mov [temp42], eax
;else if(((a*q-p*b)==0)&&((b*p-q*a)==0)&&((c*q-r*b)!=0)&&((c*p-r*a)!=0))
mov eax, [temp33]
cmp eax, '0'
sete bh
mov ebx, [temp36]
cmp ebx, '0'
sete ah
and bh, ah
mov ecx, [temp39]
cmp ecx, '0'
setne ch
and ch, bh
mov edx, [temp42]
cmp edx, '0'
setne dh
and dh, ch
je case_3_stmt
case_3_stmt:
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg14
mov edx, len14
int 0x80
call exit ; exits program
exit:
mov eax, 1
int 0x80; exit call
我正在尝试编写一个NASM程序,该程序可以解决带有两个未知数的联立方程。
使用ld -m elf_i386 -s -o prototype prototype.o
加载后,出现以下错误。可能是什么问题?
prototype.o: In function `case_2_stmt': prototype.asm:(.text+0x509): relocation truncated to fit: R_386_16 against `.bss' prototype.asm:(.text+0x510): relocation truncated to fit: R_386_8 against `.bss' prototype.asm:(.text+0x523): relocation truncated to fit: R_386_16 against `.bss'
而且我也不太确定条件语句是否正确,所以我希望进一步提出建议。