Vous êtes sur la page 1sur 2

...\RAGHGK\Documents\Atmel Studio\7.0\SB_10\SB_10\main.

asm 1
;
; SB_10.asm
;
; Created: 21-11-2019 19:41:47
; Author : Shreesha Bhaktha
;

; Replace with your application code


.equ inputA=$ab ;input address
.equ GCT=$FF ;given condition true
.EQU GCF=$00 ;given condition false
.EQU MSB_CHECK=$E0 ;checking for zeros in first three MSBs
.EQU CHECK_ONES=$01 ;compare value for checking ones
.ORG $0000
RESET: JMP START
.ORG $0040
START: LDI ZL,LOW(inputA<<1);initialize zpointer
LDI ZH,HIGH(inputA<<1)
LPM R0,Z ;load r0
LDI R16,GCT
MOV R10,R16 ;GCT
LDI R16,GCF
MOV R11,R16 ;GCF
LDI R18,$00 ;ZEROS COUNTER
LDI R17,$00 ;ONES COUNTER
LDI R16,MSB_CHECK
AND R0,R16 ;here MSB is checked
BREQ MSBT ;if MSBs are zero branch
STS $0100,R11 ;if not branched store GCF
STOP: RJMP STOP ;stop here
MSBT: LPM R0,Z ;load r0
MOV R1,R0 ;initialize r1 for right through carry shifting
HERE: LDI R16,CHECK_ONES
AND R16,R1 ;2 out of 5 ones are checked
BRNE ONET ;if one is present branch
LDI R16,CHECK_ONES; if not branched
ADD R18,R16 ;zero counter increment
MOV R19,R18 ;dummy register r19
ADD R19,R17 ;adding zero counter and ones counter
CPI R19,$05 ;comparing whether if it is equal to 5
BRNE SHIFT ;if it is not equal to 5 then branch
CPI R17,$02 ;checking whether number of ones
BREQ TWOONE ;if there are 2 ones then branch
STS $0100,R11; if not branched store GCF
STOP2: RJMP STOP2 ;stop here
ONET: ADD R17,R16 ;incrementing ones counter
SHIFT: ROR R1 ;right shifting r1 through carry
LDI R16,CHECK_ONES
MOV R20,R17 ;creating dummy register
ADD R20,R19 ;adding zero counter and ones counter
CPI R20,$05 ;comparing whether if it is equal to 5
BREQ STOP ;if it is 5 branch to stop
JMP HERE; if not branched jump here
TWOONE: STS $0100,R10 ;store GCT
STOP1: RJMP STOP1 ;stop here
...\RAGHGK\Documents\Atmel Studio\7.0\SB_10\SB_10\main.asm 2
.ORG inputA
.DB $EF
.DSEG

Vous aimerez peut-être aussi