Sie sind auf Seite 1von 10

################## DATA SECTION ##################

02 .data
03 prompt: .asciiz "\n How many integer numbers?(5 integers,minimum)"
04 result: .asciiz "The minimum integer is "
05
06 ################## CODE SECTION ##################
07 .text
08 .globl main
09 main:
10 li $v0, 4 # system call code for Print String
11 la $a0, prompt # load address of prompt into $a0
12 syscall # print the prompt message
13
14 li $v0, 5 # system call code for Read Integer
15 syscall # reads the value into $v0
16
17 blez $v0, end # branch to end if $v0 < = 0
18 li $t0, 0 # clear register $t0 to zero
19 loop:
20 add $t0, $t0, $v0 # sum of integers in register $t0
21 addi $v0, $v0, -1 # summing integers in reverse order
22 bnez $v0, loop # branch to loop if $v0 is != zero
23
24 li $v0, 4 # system call code for Print String
25 la $a0, result # load address of message into $a0
26 syscall # print the string
27
li $v0, 1 # system call code for Print
28
Integer
29 move $a0, $t0 # move value to be printed to $a0
30 syscall # print sum of integers
31 b main # branch to main
32 end: li $v0, 4 # system call code for Print String
33 la $a0, # load address of msg. into $a0
34 syscall # print the string
35 li $v0, 10 # terminate program run and
36 syscall # return control to system

rite an assembler program which


(a) prompts the user to enter data through the keyboard. The data should be
composed of positive and negative integers separated by ','. The program should
read all the data until a carriage return (enter) is pressed. The data could be single or
double digit and with '+' or '-' sign in front. The user will enter at most 10 values;
(b) calculates the average and the minimum and the maximum values of the data
entered;
(c) displays the calculated average and minimum and maximum values;
(e) prompts the user to stop or to enter new data and exits or loops back depending
on the character entered by the user.
This is problem 4 from the midterm exam. Students who correctly solve the problem
at home and bring me the solution will get bonus points to be added to the grade of
the Midterm exam. No grade will be given to partial or incomplete solutions. Grading
policy will be as follows:

You may work in groups of up to three people - i.e., 1 or 2 or 3 people in one


group. The bonus points obtained will be shared between the group members - 1
person group gets all the points awarded to the group, 2 persons group each
member gets 0.8 of the awarded points to the group, 3 persons group each
member gets 0.6 of the awarded points to the group.

The first group which solves the problem by Friday night (by midnight) will get
20 points, the second group 16 points, the third group 12 points, the forth group 8
points, the fifth group 4 points, the sixth and the following groups will get 2
points.

If the solution is submitted on Saturday (by midnight) the above points will be
multiplied by 0.8.

If the solutions are submitted on Sunday (by midnight) the above points will be
multiplied by 0.6.

No solution will be accepted next week.

Each group needs to post its members to moodle page of the course.

Solutions (the assembly code) should be submitted by one member of the


group.
Maximumu yapma:

.MODEL SMALL
.STACK 32
.DATA
DIZI DB 2,3,1,5
.CODE
ANA PROC FAR
MOV AX,@DATA
MOV DS,AX

MOV CX,3
LEA SI,DIZI
BAS:
MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JA BUYUK
JNA KUCUK
BUYUK:
MOV CL,AL
INC SI
DEC CX
CMP CX,0
JE BITIR
KUCUK:
INC SI
DEC CX
CMP CX,0
JE BAS
BITIR:
MOV AH,4CH
INT 21H
ANA ENDP
END ANA

data segment

dizi db 3,4,6,7,8,9

enbuyuk db ?

ends

stack segment

dw 128 dup(0)

ends

code segment

start:

mov ax,@data
mov ds,ax

mov es,ax

lea si,dizi

mov bl,[si]

mov cx,5

dongu :

inc si

cmp bl,[si]

ja degis

devam:

loop dongu

jmp son

degis :

mov bl,[si]

jmp devam

son :

mov enbuyuk,bl

mov ax,4c00h

int 21h

ends

end start

en buyuk

data segment

dizi db 3,4,6,7,8,9

enkucuk db ?

ends

stack segment

dw 128 dup(0)
ends

code segment

start:

mov ax,@data

mov ds,ax

mov es,ax

lea si,dizi

mov bl,[si]

mov cx,5

dongu :

inc si

cmp bl,[si]

jb degis

devam:

loop dongu

jmp son

degis :

mov bl,[si]

jmp devam

son :

mov enkucuk,bl

mov ax,4c00h

int 21h

ends

data segment
LIST DB 05H, 31H, 34H, 30H, 38H, 37H

SIZE=$-OFFSET LIST

MINIMUM DB ?

MAXIMUM DB ?

AVARAGE DB ?

ends

stack segment

DW 128 DUP(0)

ends

code segment

start proc far


MOV AX,DATA

MOV DS, AX

MOV ES,AX

MOV CX,SIZE

LEA SI,LIST

MIN:

LEA DI,MINIMUM
MOV AL,[SI]

CMP AL,[SI+1]

ADD SI, 1

LOOP MIN

MOV CX, SIZE

LEA SI, LIST

MAX:

LEA DI,MAXIMUM

MOV AL,[SI]

CMP AL,[SI-1]
ADD SI, 1

LOOP MAX

MOV CX, SIZE

LEA SI, LIST

AVG:

LEA DI, AVARAGE

ADD AX, [SI]

ADD SI, 1

LOOP AVG

MOV BX, SIZE

DIV BX
MOV AX,4C00H

INT 21H

start endp

ends

end start

ret

Das könnte Ihnen auch gefallen