1 / 9

IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.x: Tugas No. 1

IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.x: Tugas No. 1. Sumber : 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization , ed-5 3. Materi kuliah CS61C/2000 & CS152/1997, UCB 4. Intel Architecture Software Developer’s Manual. 17 Maret 2004

feivel
Download Presentation

IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.x: Tugas No. 1

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. IKI10230Pengantar Organisasi KomputerKuliah no. 05.x: Tugas No. 1 Sumber:1. Paul Carter, PC Assembly Language2. Hamacher. Computer Organization, ed-53. Materi kuliah CS61C/2000 & CS152/1997, UCB4. Intel Architecture Software Developer’s Manual 17 Maret 2004 L. Yohanes Stefanus (yohanes@cs.ui.ac.id)Bobby Nazief (nazief@cs.ui.ac.id) bahan kuliah: http://www.cs.ui.ac.id/kuliah/POK/

  2. Tugas Pemrograman #1: Vector Add • CVEC = AVEC + Const * BVEC for (i = 0; i < vlength; i++) { CVEC[i] = AVEC[i] + Const * BVEC[i] } • AVEC, BVEC, CVEC, Const, vlength disimpan di memori • Ukuran elemen vektor (AVEC[i], BVEC[i], CVEC[i]), Const, vlength: 4-byte (integer)

  3. Instruksi: ADD & MUL • ADD DEST,SRC ; DEST  [SRC] + [DEST] • DEST, SRC: register-/memory-operand • salah satu dari DEST atau SRC harus berupa register-operand • MUL SRC32 ; EDX:EAX  [SRC32] * [EAX] • MUL DWORD [DATA] • MUL EBX

  4. Instruksi: JNZ mov ecx,[Counter] ; ecx serves as a counter. L1: ... dec ecx jnz L1; if (ecx != 0) then jump to L1

  5. vector_add.asm %include "asm_io.inc“ segment .data ; initialized data is put in the data segment here segment .bss ; uninitialized data is put in the bss segment segment .text global _asm_main _asm_main: enter 0,0 ; setup routine pusha ; code is put in the text segment. Do not modify the code before ; or after this comment. popa mov eax, 0 ; return back to C leave ret

  6. Kompilasi • nasm –f coff vector_add.asm • gcc –o vector_add.exe driver.c vector_add.o asm_io.o

  7. (Salah Satu) Solusi • %include "asm_io.inc" • segment .data • AVEC dd 0x00111111,0x00222222,0x00333333,0 • BVEC dd 0x01000000,0x02000000,0x03000000,0 • CVEC dd 0,0,0,0 • Const dd 16 • N dd 3 • segment .text • global _asm_main • _asm_main: • enter 0,0 • pusha • mov esi,AVEC ; esi points to vector A. • mov ebx,BVEC ; ebx points to vector B. • mov edi,CVEC ; edi points to vector C. • mov ecx,[N] ; ecx serves as a counter.

  8. (Salah Satu) Solusi • L1: • mov eax,[ebx] ; EAX = BVEC[i] • mul dword [Const] ; EDX:EAX = Const * BVEC[i] • add eax,[esi] ; EAX = Const*BVEC[i] + AVEC[i] • mov [edi],eax ; CVEC[i] = EAX • add ebx,4 ; EBX  BVEC[i++] • add esi,4 ; ESI  AVEC[i++] • add edi,4 ; EDI  CVEC[i++] • dec ecx ; Decrement the counter. • jnz L1 ; Loop again if not done. • popa • mov eax,0 • leave • ret

  9. Pengamatan & Diskusi • Alokasi vektor AVEC, BVEC, dan CVEC • Penggunaan register • sebagai pointer (esi, edi, ebx) • sebagai variabel sementara (eax, ecx, edx) • alokasi Const di memori tidak optimal!

More Related