EASY 68K (ASSEMBLY LANGUAGE) 1. Initialize an array [14, 7, 1, 17, 10]. Then Pri
ID: 3818826 • Letter: E
Question
EASY 68K (ASSEMBLY LANGUAGE)
1. Initialize an array [14, 7, 1, 17, 10]. Then
Print it out. (2)
Find out greatest and least numbers in this array and print them out in two lines. (3)
Desired output:
14 7 1 17 10
17
1
2. Initialize an array [1, 7, 13, 0, 11, 24, 8].
Load a number from keyboard. (1)
If the number is negative, print out odd elements of the array. Otherwise, print out even elements. Do not forget the commas. (4)
Example output:
1, 7, 13, 11
Or:
0, 24, 8
3. Given an array [3, -1, 0, 4]
Initialize the array. (1)
Print out these elements in ascending order. Do not forget commas and brackets. (6)
Example output:
[-1, 0, 3, 4]
Explanation / Answer
1.)
START: ORG $890 // start program
CLR.B D0
LEA Array,AR
MOVE.B #ARRAY_SIZE,D2 // array size is 5 here
MOVE.B #5,D3
MOVE.B #14,0(AR)
MOVE.B #7,1(AR)
MOVE.B #1,2(AR)
MOVE.B #17,3(AR)
MOVE.B #10,4(AR) // array becomes [14,7,1,17,10]
//NOTE yu could also initialise array like
//Data Segment
ARR DB 14,7,1,17,10
//CODE
LEN DW $-AR
MIN DB ?
MAX DB ?
//CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
LEA SI,AR
MOV AL,AR[SI]
MOV MIN,AL
MOV MAX,AL
MOV CX,LEN
REPEAT:
MOV AL,AR[SI]
CMP MIN,AL
JL FINDMAX
MOV MIN,AL
FINDMAX:
CMP MAX,AL
JG OK
MOV MAX,AL
OK:
INC SI
LOOP REPEAT
MOV AH,4CH
INT 21H
END START
2.)
START: ORG $690 // start program
CLR.B D5
LEA Array,AR
MOVE.B #ARRAY_SIZE,D6 // array size is 7 here
MOVE.B #7,D7
MOVE.B #1,0(AR)
MOVE.B #7,1(AR)
MOVE.B #13,2(AR)
MOVE.B #0,3(AR)
MOVE.B #11,4(AR)
MOVE.B #24,5(AR)
MOVE.B #8,6(AR) // array becomes [1, 7, 13, 0, 11, 24, 8]
//NOTE yu could also initialise array like this
//Data Segment
ARR DB 1, 7, 13, 0, 11, 24, 8
//CODE
li $v0, 5
syscall
move $t0, $v0 // read integer from console : value is in $t0
// to check whther number is negative/ positive: compare it with zero
cmp e$toax, 0 ; Compare the number to zero
jge positive
//else negative here
//pront elements at position 1,3,5,7
positive:
//pront elements at position 0,2,4,6
3.)
START: ORG $490 // start program
CLR.B D2
LEA Array,AR
MOVE.B #ARRAY_SIZE,D3 // array size is 4 here
MOVE.B #4,D4
MOVE.B #3,0(AR)
MOVE.B #-1,1(AR)
MOVE.B #0,2(AR)
MOVE.B #4,3(AR) // array becomes [3, -1, 0, 4]
//NOTE yu could also initialise array like this
//Data Segment
ARR DB 3,-1,0,4
MOV AX,DATA
MOV Data_segment,AX
MOV CH,04H
ONE: MOV CL,04H
LEA SI,AR
TWO: MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JC OTHER
MOV HK,[SI+1]
XCHG [SI],HK
MOV [SI+1],HK
OTHER: INC SI
DEC CL
JNZ TWO
DEC CH
JNZ ONE
INT 3
END START
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.