[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Assembly Language

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 14
Thread images: 1

File: badcode.gif (31KB, 657x352px) Image search: [Google]
badcode.gif
31KB, 657x352px
Bad engineering student here, I've been given this assignment:
Write a program to count the number of elements in an array whose bits 3, 4, and 7 are zeros. The array has N 8-bit elements and is stored in memory locations starting from $1000
This is for the hcs12 processor, any advice on how to get started?
>>
This thread is getting me all curious if there's any actually clever and educated people lurking around here.
>>
>>57372111
I'm an engineering grad student and I'm pretty new to pure assembly language. It makes me feel dumb not knowing how to do this simple assignment.
>>
>>57371873
>any advice on how to get started?
Read the book and do your own damn homework.
>>
>>57371873
your basic tool is masking
for a byte B, the 3rd, 4th, and 7th bits == 0 iff
B & 0x00101100 == 0


that is, the and operator lets you "select" bits by using a mask. that is the basic solution, but from here you can do a lot more, for example you can process multiple bytes in parallel by working with 32 or 64-bit chunks at a time
>>
>>57371873
First I'd fill all of the of the memory locations with FFs. Load the array with your data. Then loop through each memory location loading your A register with the contents of each location. Then AND Register A with 01001100. if the value is greater than 0 you should add 1 to the counting location.
>>
>>57372221
Oops ment if the value is 0 add 1 to the counting location.
>>
thanks for the feedback, i honestly expected to get trolled
>>
got it to work, thanks boys!
>>
>>57373616
Come back later and let us know how your teacher liked it, okay buddy?
>>
>>57373640
the professor will take forever to grade it, if he does soon ill make a tread about!
>>
>>57371873
Isn't this impossible? or at least a question of probability?

You could say "mask it with 0b10011000" and check if it equals 0, but it's possible that whatever data lies outside of the array may happen to contain zeroes in those positions as well.

And if you say "copy the array into an area which has been initialized with just 1's or just 0's" wouldn't that require you to know what area you are copying? And if you know how much memory to copy, you would already know the size of the array.

If any uninitialized memory is guaranteed to be a certain value then this is possible, but otherwise that wouldn't be a safe assumption, no?
>>
So i've made a program that counts 0's in memory locations $1000-$1001 and it saves it in 1005

Here's the code:
org $1000
dc.w $2355
zero_cnt rmb 1
lp_cnt rmb 1
org $1500
clr zero_cnt
movb #16,lp_cnt
ldd $1000
again lsrd
bcs chk_end
inc zero_cnt


any hints on how to only get it to count the 3,4 and 7th bit?
>>
>>57376040
didn't get tail end of code
org $1000
dc.w $2355
zero_cnt rmb 1
lp_cnt rmb 1
org $1500
clr zero_cnt
movb #16,lp_cnt
ldd $1000
again lsrd
bcs chk_end
inc zero_cnt
chk_end dec lp_cnt
bne again
forever bra forever
end
Thread posts: 14
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.