КАПУСТА: почитай,обсуди,отдохни!

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » КАПУСТА: почитай,обсуди,отдохни! » Ассемблер » Лабы по Ассемблеру


Лабы по Ассемблеру

Сообщений 11 страница 13 из 13

11

Итак 6, последняя в этом семестре:
задание:
-вводим данные используя int21h
-проводим вычисление формулы: a / b * (a - b)
-выводим результат через int21h
-выводим результат посредством прямого доступа к видеопамяти

.model small
.stack 100h
.data
max db 7
len db ?
number db 7 dup (?)

mess_1 db 'Please, input your first number:$'
mess_2 db 0Dh,0Ah,'Please, input your second number:$'
result_msg db 0Dh,0Ah,'Result of the computation is: (number_1/number_2)*(number_1-number_2):$'
next_line dw 000A0h

number_1 dw ?
number_2 dw ?
result_number dw ?

result db 7 dup (?)
tmp dw 10
.code

begin:

    mov ax,@data
    mov ds,ax
   
    mov ax,0003h    ;clear screen
    int 10h
   
    push 0B800h     ;initialize es
    pop es
   
    mov ah,9        ;output 1st message
    lea dx,mess_1
    int 21h

    lea dx,max      ;convert to a number 
    mov di,dx
    call input         
    mov number_1,ax
   
    mov ah,9        ;output 2d message
    lea dx,mess_2
    int 21h

    lea dx,max         
    mov di,dx
    call input      ;convert to a number     
    mov number_2,ax
   
    mov ah,9        ;output the result message
    lea dx,result_msg
    int 21h

    mov ax,number_1
    mov bx,number_2
    cwd
    idiv bx
    push ax
    mov ax,number_1
    sub ax,number_2
    pop bx
    imul bx
    mov result_number,ax
   
    call int_to_str
    mov ah,9
    lea dx,result
    int 21h

    mov ax,next_line  ;output result on next line with another color
    mov bx,3
    mul bx
    mov di,ax
    lea si,result
    call print_str
   
    xor ah,ah         ;waiting until pressed any key
    int 16h

    mov ax,4c00h      ;exit code
    int 21h

    print_str proc

next:             ;input: DI - start point
   
    lodsb
    cmp al,'$'
    jz exit
   
    mov ah,10b
    stosw
    jmp next
   
exit:
   
    ret
    print_str endp
   
str_to_int proc

; procedure that converts string into the number
; input: DI - offset of string
; BH = 1 - there is a sign in the number (- or +)
; BH = 0 - there is a number without '-' or '+'
; BL = 1 - number > 0
; BL = 0 - number < 0

push di
push cx
xor cx,cx
add di,2       ; di - offset of string
cmp bh,1       ; if the number with '-' or '+', then we adding to di number 1
jne skip_      ; else skip
add di,1
mov cl,byte ptr [di-2] ;cl - counter
dec cl
jmp skip_s
skip_:
mov cl,byte ptr [di-1]

skip_s:

xor ax,ax
push bx
xor bx,bx

n1:
mov bl,byte ptr [di]   ;convertion string->number, offset di
sub bl,30h
mul tmp
add ax,bx
inc di
loop n1
pop bx
or bl,bl               ; checking the range
jnz skip_plus
cmp ax,7FFFh           ; if number>0, then range is 0 .. 32767
ja error_sti           ; if result > 7FFFh, then error
jmp exit_sti           ; exit

skip_plus:
cmp ax,8000h           ; if number<0, then range is 0 .. 32768
ja error_sti           ; if result > 7FFFh, then error
neg ax
jmp exit_sti           ; exit

error_sti:
mov bx,0FFFFh     ; bx = FFFFh, procedure error

exit_sti:
pop cx
pop di
ret
str_to_int endp

int_to_str proc
; convertion of the number to the string
; input: AX - number
; output: result - string's buffer

push cx
push bx
push di
push si
xor si,si
cmp ax,7FFFh
jna convert_plus
mov byte ptr result[si],'-'                 
inc si
neg ax

convert_plus:     
xor cx,cx
xor dx,dx
nn:
cwd
div tmp
add dx,30h
push dx
inc cx
cmp ax,0
jne nn

pp:
pop ax
mov byte ptr result[si],al
inc si
loop pp
mov byte ptr result[si],'$'

pop si
pop di
pop bx
pop cx

ret
int_to_str endp

input proc     
mov ah,0Ah
int 21h
xor bx,bx
cmp byte ptr [di+2],2dh
jne not_neg

mov bh,1               
mov bl,1

not_neg:

cmp byte ptr [di+2],2bh
jne call_proc

mov bh,1               
mov bl,0               

call_proc:

call str_to_int
ret
input endp

end begin

0

12

Хм... Спасибо,это весьма понадобится- у нас со следущего семестра ассемблер:)
Кстати,на будущее, когда вставляешь код юзай специальную закладку "код",недалеко возле смайликов- более читабельно:)

0

13

Ок, спасибо!

0


Вы здесь » КАПУСТА: почитай,обсуди,отдохни! » Ассемблер » Лабы по Ассемблеру