I started AVR Studio 6.2 on my Windows machine. Clicked on File>>New>>Project, selected New Projec>>Assembler then selected the mega328P for the chip.
I went to this page: http://www.instructables.com/id/Command-Line-Assembly-Language-Programming-for-Ard-2/ and copied the code from step 3 into the editor into Studio. I commented out the two rcall delay lines in the blink loop.
I went to Menu: Build>>Build Solution. I got a "Build succeeded." message. Looking good!
I went to Menu: Debug>>Windows and selected I/O View. A window popped up. I clicked on the I/OPORTD selection to expand it. At the bottom of the window the contents of registers PIND, DDRD and PORTD are displayed.
I went to Menu: Debug and selected "Start debugging and break" The simulator jumped into the code window and the I pressed F11 (the step into key) and watched how the highlighted line increments. Take a look what happens to PORTD and PIND when you get into the blink loop.
Modify the code to do what you want from there. I think that should get you going.
EDIT: Just to make sure everything works I modified the code to blink all of PORTB so you can see how it's done.
Good Luck.
/*
* AssemblerApplication2.asm
*
* Created: 7/31/2015 6:25:07 AM
* Author: JMB
*/
.nolist
.include "./m328Pdef.inc"
.list
;==============
; Declarations:
.def temp = r16
.def overflows = r17
.org 0x0000 ; memory (PC) location of reset handler
rjmp Reset ; jmp costs 2 cpu cycles and rjmp costs only 1
; so unless you need to jump more than 8k bytes
; you only need rjmp. Some microcontrollers therefore only
; have rjmp and not jmp
.org 0x0020 ; memory location of Timer0 overflow handler
rjmp overflow_handler ; go here if a timer0 overflow interrupt occurs
;============
Reset:
ldi temp, 0b00000101
out TCCR0B, temp ; set the Clock Selector Bits CS00, CS01, CS02 to 101
; this puts Timer Counter0, TCNT0 in to FCPU/1024 mode
; so it ticks at the CPU freq/1024
ldi temp, 0b00000001
sts TIMSK0, temp ; set the Timer Overflow Interrupt Enable (TOIE0) bit
; of the Timer Interrupt Mask Register (TIMSK0)
sei ; enable global interrupts -- equivalent to "sbi SREG, I"
clr temp
out TCNT0, temp ; initialize the Timer/Counter to 0
sbi DDRD, 4 ; set PD4 to output
ldi temp, 0b11111111 ; going to set PORTB to outputs
out DDRB, temp ; it"s outputs
;======================
; Main body of program:
blink:
ldi temp, 0b11111111
out PORTB, temp
sbi PORTD, 4 ; turn on LED on PD4
;rcall delay ; delay will be 1/2 second
ldi temp, 0b00000000
out PORTB, temp
cbi PORTD, 4 ; turn off LED on PD4
;rcall delay ; delay will be 1/2 second
rjmp blink ; loop back to the start
delay:
clr overflows ; set overflows to 0
sec_count:
cpi overflows,30 ; compare number of overflows and 30
brne sec_count ; branch to back to sec_count if not equal
ret ; if 30 overflows have occured return to blink
overflow_handler:
inc overflows ; add 1 to the overflows variable
cpi overflows, 61 ; compare with 61
brne PC+2 ; Program Counter + 2 (skip next line) if not equal
clr overflows ; if 61 overflows occured reset the counter to zero
reti ; return from interrupt