ASM2

Tinh tong day so nguyen

INCLUDE lib1.asm

.MODEL small

.STACK 100h

.DATA

M1 db 13,10,'Hay vao so luong thanh phan : $'

M2 db 13,10,'a[$'

M3 db '] : $'

M4 db 13,10,'Day so vua vao la : $'

M5 db ' $'

M6 db 13,10,"Tong day so nguyen la : $"

M7 db 13,10,"Co tiep tuc chuong trinh ko (C/K) ? $"

sltp dw ?

i dw ?

a dw 100 dup(?)

.CODE

PS:

mov ax,@data

mov ds,ax

CLRSCR

HienString M1

call VAO_SO_N

mov sltp,ax

; vong lap nhan cac so vao mang

mov cx,ax

lea bx,a

mov i,0

L1:

HienString M2

mov ax,i

call HIEN_SO_N

HienString M3

call VAO_SO_N

mov [bx],ax

inc i

add bx,2

loop L1

;vong lap dua cac so len man hinh

HienString M4

mov cx,sltp

lea bx,a

L2:

mov ax,[bx]

call HIEN_SO_N

HienString M5

add bx,2

loop L2

;Vong lap tinh tong

HienString M6

mov cx,sltp

lea bx,a

xor ax,ax

L3:

add ax,[bx]

add bx,2

loop L3

;Thong bao

call HIEN_SO_N

HienString M7

mov ah,1

int 21h

cmp al,'c'

jne Exit

jmp PS

Exit:

mov ah,4ch

int 21h

INCLUDE lib2.asm

END PS

TONG THANH PHAN AM

L3:

mov dx,[bx]

and dx,dx

jns L4

add ax,[bx]

L4:

add bx,2

loop L3

TONG THANH PHAN DUONG

L3:

mov dx,[bx]

and dx,dx

js L4

add ax,[bx]

L4:

add bx,2

loop L3

TONG THANH PHAN CHAN

L3:

mov dx,[bx]

shr dx,1

jc L4

add ax,[bx]

L4:

add bx,2

loop L3

TONG THANH PHAN LE

L3:

mov dx,[bx]

shr dx,1

jnc L4

add ax,[bx]

L4:

add bx,2

loop L3

Tinh trung binh cong :

File CPP

#include<iostream.h>

#include<conio.h>

int so1,so2,flag=0;

extern int TRB();

void main(void)

{

clrscr();

cout<<"

Hay vao so thu 1 :";

cin>>so1;

cout<<"

Hay vao so thu 2 :";

cin>>so2;

cout<<"Trung binh cong cua 2 so nguyen la : "<<TRB()+0.5*flag;

getch();

}

File ASM

.MODEL large

.DATA

EXTRN _so1:word,_so2:word,_flag:word

.CODE

PUBLIC @TRB$qv

@TRB$qv PROC

mov ax,_so1 ; ax = so1

mov bx,_so2 ; bx = so2

add ax,bx ; ax = ax + bx

sar ax,1 ; Chia doi lam tron duoi

jnc L1 ; Neu tong la chan (C=0) thi nhay den L1

mov cx,1

mov _flag,cx

L1:

ret

@TRB$qv ENDP

END

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: #thuyết