0

Why doesn’t std::cout print?

#include <iostream> using namespace std; int disassemble8080(int programCounter, unsigned char* codeBuffer) { short OPsize = 1; switch(codeBuffer[programCounter]) { case 0x00: cout << "NOP\n"; break; case 0x01: cout << "LXI B " << codeBuffer[programCounter + 0x02] << codeBuffer[programCounter + 0x01]; OPsize = 3; break; } return OPsize; } int main() { unsigned char myCodes[10]= {1, 34, 12}; disassemble8080(0, myCodes); cout.flush(); return 0; } This doesn’t print anything, even after cout::flush

19th Dec 2019, 1:52 PM
Jason Guo
3 Respostas
+ 1
Coder Kitten Gregor Dietrich i found the solution. so basically the unsigned char was being interpreted as the corresponding ascii code when I wanted it to be an integer. I fixed this by casting the print to print the integer version of the unsigned char. I am worried that the cast will increase the size of the 1 byte integer, because the system that I am emulating only works with unsigned char.
19th Dec 2019, 5:10 PM
Jason Guo
0
I've never even heard of the flush() method, you probably don't need it. best bet would be that your switch cases are never triggered. are you sure codeBuffer[programCounter] evaluates to 0x00/0x01? try putting a cout << codeBuffer[programCounter]; right at the beginning of your disassemble8080() function and see what you get.
19th Dec 2019, 2:43 PM
grdr
0
maybe I missed something but 1 is generally not the same as 0x01
19th Dec 2019, 2:53 PM
grdr