[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]

asm counting 1 bits help

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: 13
Thread images: 3

File: images (1).jpg (5KB, 225x225px) Image search: [Google]
images (1).jpg
5KB, 225x225px
my goal is to count the number of 1 bits in an input.
The inputs are done in C, just have to write the asm.

I think I have the counter done I just don't know what to do from here...
Currently it runs but there is no output.....
Here is my asm:
.CODE ; contains our code

isBitCountEven PROC PUBLIC
PUSH ebp ; save caller base pointer
MOV ebp, esp ; set our base pointer
SUB esp, (1 * 4) ; allocate uint32_t local vars
PUSH edi
PUSH esi
; end prologue


MOV al, [ebp + 8]
AND al, 1 ; convert to binary

;now walk down the variable and count the number of 1
SHIFT:
SHL al, 1
JNC SKIP
INC ebx
SKIP:
loop SHIFT

FINALE: ;see if it adds up to ebx
CMP ebx, 2
JE TRUE
CMP ebx, 4
JE TRUE
CMP ebx, 6
JE TRUE
CMP ebx, 8
JE TRUE
JMP FALSE
TRUE:
MOV eax,1
POP esi ; start epilogue
POP edi
MOV esp, ebp ; deallocate locals
POP ebp ; restore caller base pointer
RET
FALSE:
MOV eax, 0
POP esi ; start epilogue
POP edi
MOV esp, ebp ; deallocate locals
POP ebp ; restore caller base pointer
RET
isBitCountEven ENDP ; end the procedure
END isBitCountEven


here is the C/C++
//--------------------------------------------------------------------------------------------------------------------
#include <stdint.h>
#include <stdio.h>
#include <iostream>
using namespace std;

extern "C" {
bool isBitCountEven(int32_t);
}

static int32_t testData[] = {
0x0,
0x1,
0x2,
0x4,
0x8,
0x40000000,
0x80000000,
0x00000002,
0xe,
0xff770001,
0xffeeeeff,
0xdeadbeef,
0xbaddf00d,
0xd00fefac,
0xfaceecaf,
0xffffffff,
0xaaaa5555
};
#define NUM_TEST_CASES (sizeof (testData) / sizeof (*testData))


int main()
{
printf("ICE#10 \n\n");

for (int i = 0; i < NUM_TEST_CASES; i++) {
printf("isBitCountEven(0x%8x) yields: %s\n", testData[i], isBitCountEven(testData[i]) ? "true" : "false");
}
system("PAUSE");
return 0;
}
>>
Pop a popcnt in there.
>>
>>59779473
what does that do and where? we haven't learned that...
>>
>>59779488
>POPCNT — Return the Count of Number of Bits Set to 1

http://www.felixcloutier.com/x86/POPCNT.html
>>
>>59779473>>59779501

i should've googled it my bad, i don't think it works i tried putting it in a few places and i said "instruction or register not accepted in current CPU mode"

here some extra details:
its x86 flat pannel model set
80386 instruction set
>>
File: 04070245.png (249KB, 1223x1715px) Image search: [Google]
04070245.png
249KB, 1223x1715px
>>
>>59779540
I don't think I would be allowed to use this because we haven't learned it in class.
>>
>>59779579
It's Intel's manual.
https://software.intel.com/en-us/articles/intel-sdm
>>
>>59779602
I still would not like to use it/ dont know where to put it. What is the most basic way i could obtain my goal with what i have?
>>
File: 04073153.png (61KB, 863x1143px) Image search: [Google]
04073153.png
61KB, 863x1143px
>>
>>59779436
Иди нaхyй я хoчy asmr
>>
>>59779436
popcnt is a very new instruction. Your class uses 386's ISA as far as I can tell, so you simply don't have it available.
>>
http://www.hackersdelight.org/hdcodetxt/pop.c.txt
Thread posts: 13
Thread images: 3


[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.