Beruflich Dokumente
Kultur Dokumente
language
1
¡ 0 to +15 +6
+5
0110
0101
0110
0101
0110
0101
3+4 3 + -4 -3 + 4 -3 + -4
0011 0011 1101 1101
+ 0100 + 1100 + 0100 + 1100
= 0111 = 1111 = 0001 = 1001
(7) (-1) (+1) (-7)
Exercise: Fill out the same table using sign magnitude numbers.
Do you understand now why 2’s complement is a useful
representation!
M. Neil - Microprocessor Course
8 Bit representations
16
R28:R29 is Y
R30:R31 is Z
If they are not equal, the next instruction will branch back to location 0xC2
that is loop back if they are equal it continues on (and returns from main)
M. Neil - Microprocessor Course
Compare assembly language to c
22
int main(void) 000000be <main>:
{ be: 80 e0 ldi r24, 0x00 ;0
c0: 90 e0 ldi r25, 0x00 ;0
char i;
c2: 98 0f add r25, r24
char j; c4: 92 bb out 0x18, r25 ; 18
i=0; c6: 82 bb out 0x18, r24 ; 18
c8: 8f 5f subi r24, 0xFF ; 255
j=0;
ca: 8a 30 cpi r24, 0x0A ; 10
while (i<10) { cc: d1 f7 brne .-12 ; 0xc2 <main+0x4>
j = j + i; ce: 80 e0 ldi r24, 0x00 ;0
PORTB = j; d0: 90 e0 ldi r25, 0x00 ;0
d2: 08 95 ret
PORTB = i;
i++; • Here the variables are stored in registers r24, r25
} • Pretty easy to see how this program is translated
return 0; • More complex programs quickly become very
complicated to understand in assembly language
}
Addition Increment
add r20,r21 inc r20
R20 ß r20+r21 R20 ß r20+1
Subtraction
subi r20,$22 Logic
R20 ß r20-$22
and r20,r24
sub r20,r21
R20 ß r20-r21 R20 ß AND(r20,r24)
Branch
breq label1
Branch if equal to location label1
brlo label2
Branch if lower to location label2
If the Branch test fails – the next line of code is executed
If the Branch test is successful, the program jumps to the location specified
Jump
jmp label3
Jump to label3 – no information about where we jumped from is
saved. This is a one way trip
Call, Return
rcall mysub
ret
Call subroutine mysub. The program saves information about where it currently is
executing and then jumps to the code at mysub. When the subroutine is finished it
calls ret, which then returns to where the rcall was made.
Input Output
in r20,PIND out PORTD,r24
R20 ß PIND PORTD ß r24
The
Atmega128
The microprocessor you
will be using has several
input and output ports
PORTD Switches
PORTB LEDs
PORT connectors
Select New
Project
Create new
folder
At the
end
M. Neil - Microprocessor Course
Getting started with Studio 7:
40
Your file
Close
Simple.asm
Save then
close
Select
Simulator
Output window
appears showing a
successful build or
other wise!
M. Neil - Microprocessor Course
Building and Running your Program :
44
Some new files have
been generated
Memory window
IO window shows
many others
Processor Status
window shows
many processor
resources
Open as
required for
detailed view
Current point
in program
Here to reset
Here to pause
Here to run
Click this to
without
step through
display
programme
Power connector
ISP interface:
and switch
Programming only
JTAG interface:
Programming
and debugging
Save then
close
Select Atmel-
ICE and JTAG
interface
Current point
in program
Here to reset
Here to pause
Here to run Click here to
Click this to change bits
without
step through in regiisters
display
programme