Вы находитесь на странице: 1из 4

TEKNIK KOMPUTER

AVR Assembly
Nama : Gilang Satria Ajie
NIM : I0717017

1. Instal ATMEL Studio 7

2. Jalankan tutorial untuk upload kode assembly ke Arduino


3. Buat Program Sendiri
LED Blinking, tapi LED yang menyala 3 angka digit terakhir NIM, dengan delay ((NIM 3
digit)mod 7) detik
Menggunakan Sofware Simulasi Proteus 8.0

NIM = 017
Binary 00010001
port 0 dan port 4
Delay = 03 detik
Script Assembly
;
; AssemblerApplication1.asm
;
; Created: 5/9/2018 10:00:21 AM
; Author : Aimma
;

.ORG 0x0000 // Tells the next instruction to be written


RJMP main // State that the program begins at the main label

main:
LDI r16, 0xFF // Load the immedate value 0xFF (all bits 1) into
register 16
OUT DDRB, r16 // Set Data Direction Register B to output for all pins

loop:
SBI PortB, 0 // Set the 0 bit in PortB. (i.e. turn on the LED)
SBI PortB, 1 // Set the 4th bit in PortB. (i.e. turn on the LED)
RCALL delay_03
CBI PortB, 0 // Clear the 0 bit in PortB. (i.e. turn off the LED)
CBI PortB, 1 // Clear the 4th bit in PortB. (i.e. turn off the LED)
RCALL delay_03
RJMP loop // Loop again

// Everything beneath is part of the delay loop


delay_03:
LDI r16, 8

outer_loop:
LDI r23, low(3037)
LDI r24, high(3037)

delay_loop:
ADIW r24, 1
BRNE delay_loop
DEC r16
BRNE outer_loop
RET

Script C
/*
* GccApplication1.c
*
* Created: 5/9/2018 10:08:47 AM
* Author : Aimmma
*/

#define F_CPU 1000000UL


#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
DDRB = 0xFF;
PORTB = 0x00;
/* Replace with your application code */
while (1)
{
PINB = (1<<PB0);
PINB = (1<<PB1);
_delay_ms(3000);
}
}

Script Disassembly
--- c:\users\aimma\Documents\Atmel
Studio\7.0\GccApplication1\GccApplication1\Debug/.././main.c
{
DDRB = 0xFF;
00000040 SER R24 Set Register
00000041 OUT 0x04,R24 Out to I/O location
PORTB = 0x00;
00000042 OUT 0x05,R1 Out to I/O location
PINB = (1<<PB0);
00000043 LDI R25,0x01 Load immediate
PINB = (1<<PB1);
00000044 LDI R24,0x02 Load immediate
PINB = (1<<PB0);
00000045 OUT 0x03,R25 Out to I/O location
PINB = (1<<PB1);
00000046 OUT 0x03,R24 Out to I/O location

4. Perbandingan jumlah instruksi

- jumlah instruksi assembly ada 24 perintah


- jumlah instruksi assembly yang dikonversi dari instruksi C ada 13 perintah