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
>>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?
>>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