
Untitled
By: a guest on
Apr 27th, 2012 | syntax:
ASM (NASM) | size: 5.32 KB | hits: 22 | expires: Never
code_segment segment para public "code"
org 100h
complex struc
Re dw ?
Im dw ?
complex ends
i_1 complex<>
i_2 complex<>
EnterFailureMessage db "Ошибка ввода$"
i_1_Re_Message db "Введите целое число 1: $"
i_1_Im_Message db "Введите комплексную часть числа 1: $"
i_2_Re_Message db "Введите целое число 2: $"
i_2_Im_Message db "Введите комплексную часть числа 2: $"
AddOperation db "Сложение: $"
SubOperation db "Вычитание: $"
MulOperation db "Умножение: $"
DivOperation db "Деление: $"
buffer db 6,7 dup( ? )
assume ds:code_segment,ss:code_segment,cs:code_segment
waiting proc
mov ah, 01h
int 21h
ret
waiting endp
gonextline proc
mov dx, 0Ah
call print_symbol
int 21h
ret
gonextline endp
value_input proc
xor di, di
mov ah, 0Ah
mov dx, offset buffer
int 21h
call gonextline
mov si, offset buffer + 2
cmp byte ptr [si], '-'
jne value_position
mov di, 1
inc si
value_position:
xor ax, ax
mov bx, 0Ah
check_cycle:
mov cl, [si]
cmp cl, 0Dh
je check_end
cmp cl, 30h
jl input_error_mark
cmp cl, 39h
ja input_error_mark
sub cl, 30h
mul bx
add ax, cx
inc si
jmp check_cycle
input_error_mark:
lea dx, EnterFailureMessage
call print_string
call gonextline
jmp value_input
check_end:
cmp di, 1
jne input_proc_end
neg ax
input_proc_end:
ret
value_input endp
int_to_string proc
xor cx, cx
xor di, di
sub bx, 0
jns not_negative_value
js negative_value
negative_value:
mov dx, '-'
call print_symbol
neg bx
mov di, 1
jmp continue_parse
not_negative_value:
mov dx, '+'
call print_symbol
mov di, 0
jmp continue_parse
continue_parse:
mov ax, bx
mov dx, 0Ah
idiv dl
add ah, 30h
mov dl, ah
push dx
xor bx, bx
mov bl, al
inc cx
cmp bx, 0
jz end_of_translation
jmp continue_parse
end_of_translation:
pop dx
call print_symbol
loop end_of_translation
ret
int_to_string endp
print_symbol proc
xor ax, ax
mov ah, 02h
int 21h
ret
print_symbol endp
print_string proc
mov ah, 09h
int 21h
ret
print_string endp
end_program proc
mov ax, 4c00h
int 21h
ret
end_program endp
;---------------------------------
; Main procedure
;---------------------------------
main proc
mov ax, code_segment
mov ds, ax
lea dx, i_1_Re_Message
call print_string
call value_input
mov word ptr i_1.Re,ax
lea dx, i_1_Im_Message
call print_string
call value_input
mov word ptr i_1.Im,ax
lea dx, i_2_Re_Message
call print_string
call value_input
mov word ptr i_2.Re,ax
lea dx, i_2_Im_Message
call print_string
call value_input
mov word ptr i_2.Im,ax
;---------------------------------
; Addition
;---------------------------------
lea dx, AddOperation
call print_string
mov ax, i_1.Re
add ax, i_2.Re
mov bx, ax
call int_to_string
mov ax, i_1.Im
add ax, i_2.Im
mov bx, ax
call int_to_string
mov dx, 'i'
call print_symbol
call gonextline
;---------------------------------
; Subtraction
;---------------------------------
lea dx, SubOperation
call print_string
mov ax, i_1.Re
sub ax, i_2.Re
mov bx, ax
call int_to_string
mov ax, i_1.Im
sub ax, i_2.Im
mov bx, ax
call int_to_string
mov dx,'i'
call print_symbol
call gonextline
;---------------------------------
; Multiplication
;---------------------------------
lea dx, MulOperation
call print_string
mov ax, i_1.Re
imul i_2.Re
mov bx, ax
mov ax, i_1.Im
imul i_2.Im
neg ax
add bx, ax
call int_to_string
mov ax, i_1.Re
imul i_2.Im
mov bx, ax
mov ax, i_1.Im
imul i_2.Re
add bx, ax
call int_to_string
mov dx, 'i'
call print_symbol
call gonextline
;---------------------------------
; Division
;---------------------------------
lea dx, DivOperation
call print_string
mov dx, '('
call print_symbol
mov ax, i_1.Re
imul i_2.Re
mov bx, ax
mov ax, i_1.Im
imul i_2.Im
add bx, ax
call int_to_string
mov ax, i_1.Re
imul i_2.Im
neg ax
mov bx, ax
mov ax, i_1.Im
imul i_2.Re
add bx, ax
call int_to_string
mov dx, 'i'
call print_symbol
mov dx, ')'
call print_symbol
mov dx, '/'
call print_symbol
mov ax, i_2.Re
imul i_2.Re
mov bx, ax
mov ax, i_2.Im
imul i_2.Im
add bx, ax
call int_to_string
;------------------------------------------
; End of program
;------------------------------------------
call waiting
call end_program
main endp
code_segment ends
end main