1 / 17

Linguagem de Montagem

Linguagem de Montagem. PROVA 4 – 3/12. Exercício. Utilize o programa anterior para mostrar o maior e o menor dos três inteiros reescrevendo o procedimento e renomeando este para MINMAX. Procedimento MINMAX. segment .bbs x resw 1 y resw 1 z resw 1 segment .text ;ler x,y,z

ide
Download Presentation

Linguagem de Montagem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linguagem de Montagem PROVA 4 – 3/12

  2. Exercício • Utilize o programa anterior para mostrar o maior e o menor dos três inteiros reescrevendo o procedimento e renomeando este para MINMAX.

  3. Procedimento MINMAX segment .bbs x resw 1 y resw 1 z resw 1 segment .text ;ler x,y,z mov AX,x mov BX,y mov CX,z call MINMAX ;escrever AX MINMAX: ;entrada AX, BX, CX ;saída maior em AX ;menor em CX cmp AX, BX jge prox xchg AX,BX prox: ;AX é maior ;BX é menor cmp AX,CX jge fim xchg AX,CX mov CX,BX jmp fim2 fim: cmp CX, BX jle fim2 xchg CX,BX fim2: ret

  4. prox: ;AX é maior ;BX é menor cmp AX,CX jge fim xchg AX,CX mov CX,BX jmp fim2 fim: cmp CX, BX jle fim2 xchg CX,BX fim2: pop EBP ret MINMAX MINMAX: ;saída maior em AX ;menor em CX push EBP mov EBP, ESP mov AX,[EBP+12] mov BX,[EBP+10] mov CX,[EBP+8] cmp AX, BX jge prox xchg AX,BX segment .bbs x resw 1 y resw 1 z resw 1 segment .text ;ler x,y,z push [x] push [y] push [z] call MINMAX add ESP,6 ;escrever AX

  5. Exercício • Escreva um programa em Assembly que leia um vetor com 20 números inteiros em uma ordem qualquer e chame um procedimento ORDENA que ordena este vetor em ordem crescente.

  6. Lógica 10 > 5 10 > 8 10 > 3 10 > 2 5 10 8 3 2 5 8 10 3 2 5 8 3 10 2 5 8 3 2 10 para i=0 até 3 se p[i] > p[i+1] então troca i++

  7. Lógica j=3 repete para i=0 até j se p[i] > p[i+1] então troca i++ j-- até j=0 5 10 8 3 2 5 8 10 3 2 5 8 3 10 2 5 8 3 2 10 5 8 3 2 10 5 3 8 2 10 5 3 2 8 10 5 > 8 8 > 3 8 > 2

  8. Assembly segment .bbs vet resw 20 segment .text ;lê vet ... ORDENA: MOV EAX, 18 ;igual a j MOV ESI, 0 ; igual a i PULO1: ;troca posições INC ESI CMP ESI,EAX JLE PULO1 j=3 repete para i=0 até j se p[i] > p[i+1] então troca i++ j-- até j=0

  9. MOV ESI,0 DEC EAX CMP EAX,0 JG PULO1 segment .bbs vet resw 20 segment .text ;lê vet ... ORDENA: MOV EAX, 18 ;igual a j MOV ESI, 0 ; igual a i PULO1: ;troca posições INC ESI CMP ESI,EAX JLE PULO1 j=3 repete para i=0 até j se p[i] > p[i+1] então troca i++ j-- até j=0

  10. CMP CX,DX JLE PULO2 MOV [EBX+ESI*2],DX MOV [EBX+(ESI+1)*2],CX PULO2: INC ESI CMP ESI,EAX JLE PULO1 MOV ESI,0 DEC EAX CMP EAX,0 JG PULO1 segment .bbs vet resw 20 segment .text ;lê vet ... ORDENA: MOV EAX, 18 ;igual a j MOV ESI, 0 ; igual a i PULO1: ;troca posições MOV CX,[EBX+ESI*2] INC ESI MOV DX,[EBX+ESI*2] DEC ESI

  11. Matrizes • Matriz de 5 x 3 • Três notas de 5 estudantes • Em C • Int notas[5][3] /*5 linhas e 3 colunas*/

  12. Matrizes • Como a memória é unidimensional temos que transformar a estrutura bidimensional em unidimensional. • Esta transformação pode ser feita de duas formas: • Ordenar o vetor linha por linha começando da primeira linha (usado em C) • Ordenar o vetor coluna por coluna a partir da primeira coluna (usado em Fortran)

  13. Matrizes Linha Coluna

  14. Matrizes • Em Assembly: • Notas resd 5*3 • Aloca 60 bytes para a matriz Notas • Deslocamento: (i * colunas + j)* tamanho do elemento i = linha j = coluna Notas[3,1] = (3*3+1)*4 = 40

  15. Exemplo Segment .data Notas dw 90,89,70 dw 79,66,70 dw 70,60,77 dw 71,62,79 dw 59,76,60

  16. Exemplo Segment .text MOV ECX,5 ;n. linhas p/ loop MOV AX,0 ; guarda a soma MOV EBX,0 MOV ESI,2 ; n. colunas – 1 SOMA: ADD AX, [Notas+EBX+ESI*2] LOOP SOMA

  17. Exercício 1) Escreva um programa em Assembly para ler uma matriz de 10x10 e mostrar na tela a matriz transposta. Para obter uma matriz transposta de A, basta escrever as linhas de A como se fossem as colunas. Por exemplo: 10 11 12 10 13 16 13 14 15 transposta é 11 14 17 16 17 18 12 15 18 2) Escreva um programa em assembly que leia uma matriz de tamanho máximo 10x15 e mostre a posição do maior elemento da matriz. Seu programa deve conter um procedimento para encontrar e mostrar a posição do maior elemento.

More Related