How to understand IR checksum - reverse-engineering

I'm trying to understand how crc is calculated of below data packets of unbranded air con remote controller. it's last 4 bits seem to be crc and data packet is 8 bytes long. I can understand how to extract the data packet but not crc. First 3 bits are fixed.
data pattern eg 1) 0010 0100 0100 0011 0000 0000 0000 0000 0000 0000 1110
data pattern eg 2) 0010 1000 0101 0011 0000 0000 0000 0000 0000 0000 1101
data pattern eg 3) 0010 1000 0110 0011 0000 0000 0000 0000 0000 0000 1100
data pattern eg 4) 0010 1000 0111 0011 0000 0000 0000 0000 0000 0000 1011
data pattern eg 5) 0010 1000 1000 0011 0000 0000 0000 0000 0000 0000 1010
data pattern eg 6) 0010 1000 1001 0011 0000 0000 0000 0000 0000 0000 1001
data pattern eg 7) 0010 1000 1010 0011 0000 0000 0000 0000 0000 0000 1000
data pattern eg 8) 0010 1000 1011 0011 0000 0000 0000 0000 0000 0000 0111
data pattern eg 9) 0010 1000 0000 0011 0000 0000 0000 0000 0000 0000 0010
data pattern eg 10) 0010 1000 0001 0011 0000 0000 0000 0000 0000 0000 0001
data pattern eg 11) 0010 1000 0010 0011 0000 0000 0000 0000 0000 0000 0000
data pattern eg 12) 0010 1000 0011 0011 0000 0000 0000 0000 0000 0000 1111
sample image

I think this might be just an inverted sum.
Adding up all but last 4 bits, and then ((x&1111)^1111):
0010 + 0100 + 0100 + 0011 = 1101 -> 0010*
0010 + 1000 + 0101 + 0011 = 10010 -> 1101
0010 + 1000 + 0110 + 0011 = 10011 -> 1100
0010 + 1000 + 0111 + 0011 = 10100 -> 1011
0010 + 1000 + 1000 + 0011 = 10101 -> 1010
0010 + 1000 + 1001 + 0011 = 10110 -> 1001
0010 + 1000 + 1010 + 0011 = 10111 -> 1000
0010 + 1000 + 1011 + 0011 = 11000 -> 0111
0010 + 1000 + 0000 + 0011 = 1101 -> 0010
0010 + 1000 + 0001 + 0011 = 1110 -> 0001
0010 + 1000 + 0010 + 0011 = 1111 -> 0000
0010 + 1000 + 0011 + 0011 = 10000 -> 1111
Note that first sample is incorrect (should be 1110), but the rest match. I'm not sure if that's an error in my algorithm, or error in input data (looking at the photo, I don't see where 0010 0100 appears).
Also note that samples provided are very similar (only bits 8,9,10,11 differ, if we exclude first sample), so there are probably many ways to end up with "a solution".

Related

Binary subset rank with maximum k consecutive 0

Consider N = 6 bits
We have a set S = 2^6 = 64 binary combinations.
We want to consider a subset T of the set S based on the following criteria -
There must be <= k consecutive 0s in the subset T.
Accordingly,
If the binary number is present in subset T, calculate its rank (in binary format)
If the binary number is not present in subset T, return 0 (in binary format)
Note: We want to calculate the rank only by iterating the N bits of the given binary number, and NOT by iterating 2^N numbers.
Here is the pseudo-code -
string GetBinaryRank(string strBinaryNumber, int max_k_0s)
{
string strRankBinary = "";
if(strBinaryNumber.Contains(<= max_k_0s))
{
//calculate strRankBinary by iterating over the N bits of strBinaryNumber
for(int i = 0; i < strBinaryNumber.Length; i++)
{
if(max_k_0s == 1)
{
//calculate rank
//binary rank will be 5 bits
strRankBinary = "xxxxx";
}
else if(max_k_0s == 2)
{
//calculate rank
//binary rank will be 6 bits
strRankBinary = "yyyyyy";
}
}
}
else
{
strRankBinary = "000000";
}
return strRankBinary;
}
We want to do the rank and unrank operations for the binary number, and determine the maximum number of bits required for "strRankBinary"
Also, we want to generalize the code for "N"-bit numbers and maximum "k" consecutive 0s.
Depending on the maximum rank value, the strRankBinary must contain only the required number of maximum bits.
In the examples given below,
If max_k_0s = 1, maximum rank will be 21, which is 10101 (5 bits) in
binary.
If max_k_0s = 2, maximum rank will be 44, which is 101100 (6 bits) in
binary.
Example 1 (max 1 consecutive 0s in 6-digit binary value):
Number Rank Binary rank
-------------------------------
000000 0 00000
000001 0 00000
000010 0 00000
000011 0 00000
000100 0 00000
000101 0 00000
000110 0 00000
000111 0 00000
001000 0 00000
001001 0 00000
001010 0 00000
001011 0 00000
001100 0 00000
001101 0 00000
001110 0 00000
001111 0 00000
010000 0 00000
010001 0 00000
010010 0 00000
010011 0 00000
010100 0 00000
010101 1 00001
010110 2 00010
010111 3 00011
011000 0 00000
011001 0 00000
011010 4 00100
011011 5 00101
011100 0 00000
011101 6 00110
011110 7 00111
011111 8 01000
100000 0 00000
100001 0 00000
100010 0 00000
100011 0 00000
100100 0 00000
100101 0 00000
100110 0 00000
100111 0 00000
101000 0 00000
101001 0 00000
101010 9 01001
101011 10 01010
101100 0 00000
101101 11 01011
101110 12 01100
101111 13 01101
110000 0 00000
110001 0 00000
110010 0 00000
110011 0 00000
110100 0 00000
110101 14 01110
110110 15 01111
110111 16 10000
111000 0 00000
111001 0 00000
111010 17 10001
111011 18 10010
111100 0 00000
111101 19 10011
111110 20 10100
111111 21 10101
Example 2 (max 2 consecutive 0s in 6-digit binary value):
Number Rank Binary rank
-------------------------------
000000 0 000000
000001 0 000000
000010 0 000000
000011 0 000000
000100 0 000000
000101 0 000000
000110 0 000000
000111 0 000000
001000 0 000000
001001 1 000001
001010 2 000010
001011 3 000011
001100 4 000100
001101 5 000101
001110 6 000110
001111 7 000111
010000 0 000000
010001 0 000000
010010 8 001000
010011 9 001001
010100 10 001010
010101 11 001011
010110 12 001100
010111 13 001101
011000 0 000000
011001 14 001110
011010 15 001111
011011 16 010000
011100 17 010001
011101 18 010010
011110 19 010011
011111 20 010100
100000 0 000000
100001 0 000000
100010 0 000000
100011 0 000000
100100 21 010101
100101 22 010110
100110 23 010111
100111 24 011000
101000 0 000000
101001 25 011001
101010 26 011010
101011 27 011011
101100 28 011100
101101 29 011101
101110 30 011110
101111 31 011111
110000 0 000000
110001 0 000000
110010 32 100000
110011 33 100001
110100 34 100010
110101 35 100011
110110 36 100100
110111 37 100101
111000 0 000000
111001 38 100110
111010 39 100111
111011 40 101000
111100 41 101001
111101 42 101010
111110 43 101011
111111 44 101100

Loop storing 1s complement

Suppose a computer uses 4-bit one’s complement numbers. Ignoring overflows, what value will be stored in the variable j after the following pseudocode routine terminates?
0 → j // Store 0 in j
-3 → k // Store -3 in k
while k ≠ 0
j = j + 1
k = k - 1
end while
'''
I thought the loop would continue forever, but the answer in the back of the book says:
J (Binary) K (Binary)
0 0000 -3 1100
1 0001 -4 1011 (1100 + 1110) (where last carry is added to sum doing 1's complement addition)
2 0010 -5 1010 (1011 + 1110)
3 0011 -6 1001 (1010 + 1110)
4 0100 -7 1000 (1001 + 1110)
5 0101 7 0111 (1000 + 1110) (This is overflow -- but you can ignore)
6 0110 6 0110
7 0111 5 0101
-7 1000 4 0100
-6 1001 3 0011
-5 1010 2 0010
-4 1011 1 0001
-3 1100 0 0000
I do not understand how the k can flip to positives and the j to negatives. I do understand how they got the rows of where j =0,1,2,3,4

How much of NVS Data can we really use in ESP32?

I'm checking my NVS storage capacity. This is my output when i do make partition.
toolchain path: /home/dhananjay/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: crosstool-ng-1.22.0-80-g6c4433a
Compiler version: 5.2.0
Python requirements from /home/dhananjay/esp/esp-idf/requirements.txt are satisfied.
Partition table binary generated. Contents:
# Espressif ESP32 Partition Table
# Name, Type, SubType, Offset, Size, Flags
nvs,data,nvs,0x9000,16K,
otadata,data,ota,0xd000,8K,
phy_init,data,phy,0xf000,4K,
factory,app,factory,0x10000,1M,
ota_0,app,ota_0,0x110000,1M,
ota_1,app,ota_1,0x210000,1M,
*******************************************************************************
Partition flashing command:
python /home/dhananjay/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB1 --baud 115200 --before default_reset --after hard_reset write_flash 0x8000 /home/dhananjay/esp/Homebridge/build/partitions_two_ota.bin
dhananjay
Which shows that i can use 16k of nvs storage, yet when i write into nvs through namespace "storage" and keys "a"-"p" with each key containing 1022 bytes of data.
i get this output.
Done
String written successfully
Namespace a Completed
Done
String written successfully
Namespace b Completed
Done
String written successfully
Namespace c Completed
Done
String written successfully
Namespace d Completed
Done
String written successfully
Namespace e Completed
Done
String written successfully
Namespace f Completed
Done
String written successfully
Namespace g Completed
Done
String written successfully
Namespace h Completed
Done
String written successfully
Namespace i Completed
Done
Not enough Storage space
Wrongfull termination in Writing String
i Can only store 10220 Kb of data please help.
The 16KB is the amount of (hardware) storage. The NVS library has some overhead, though. You can see what all is consuming the storage by using the nvs_get_stats() command, documented on this page:
ESP32 NVS Library
You can experiment by erasing the partition, then running a loop that adds an entry, then calls the nvs_get_stats() routine.
One other thing to note: WIFI makes extensive use of the 'nvs' partition. I just dumped the nvs partition on a couple of boards (one had been in use, the other was 'virgin'), and found about HALF of the 16KB was used by WIFI.
I'm guessing about the data, but judging from a hex dump (below), it appears STA (client) data, AP (Access Point) data, and phy cal data was being stored there. They shouldn't NEED to store all this stuff (my app only EVER works in STA mode, and all the required parameters are hard coded in the firmware.
Also NOTE: the current (as of 2019.10.25) ESP-IDF & example code will 're-init' the nvs partition if it runs out of 'free' pages, OR discovers the format is different than the current code (in my case the bootloader use older code, and I suspect a recent app build incorporated newer code that updated the nvs format). The re-init does not appear to PRESERVE nvs contents, so DON'T expect your 'non-volatile' data to exist if you keep re-writing your flash partition.
One solution to this issue is to use a flash file system partion (such as SPIFFS) instead.
My solution is to ignore the default 'nvs' partition, and create a custom partition of 'nvs' type, to store my non-volatile data, such as described in this article
More info on the contents & use of partitions is available in the API Guide
'nvs' partition:
00000000: fcff ffff 0000 0000 feff ffff ffff ffff ................
00000010: ffff ffff ffff ffff ffff ffff 842d bab9 .............-..
00000020: aaaa 0aa8 aaaa aaaa aaaa aaaa aaaa aaaa ................
00000030: 0aa8 aaaa aaaa aaaa aaaa aaaa aaaa aafa ................
00000040: 0001 01ff 5f2b 2470 6d69 7363 0000 0000 ...._+$pmisc....
00000050: 0000 0000 0000 0000 01ff ffff ffff ffff ................
00000060: 0142 0200 7476 e997 6c6f 6700 0000 0000 .B..tv..log.....
00000070: 0000 0000 0000 0000 0400 ffff 7437 f655 ............t7.U
00000080: 0200 0000 ffff ffff ffff ffff ffff ffff ................
00000090: ffff ffff ffff ffff ffff ffff ffff ffff ................
000000a0: 0148 01ff 27e9 e5d2 6c6f 6700 0000 0000 .H..'...log.....
000000b0: 0000 0000 0000 0000 0400 0000 0100 ffff ................
000000c0: 0001 01ff 92d4 208a 6e76 732e 6e65 7438 ...... .nvs.net8
000000d0: 3032 3131 0000 0000 02ff ffff ffff ffff 0211............
000000e0: 0201 01ff f902 e2df 6f70 6d6f 6465 0000 ........opmode..
000000f0: 0000 0000 0000 0000 02ff ffff ffff ffff ................
00000100: 0242 0300 9489 8e0b 7374 612e 7373 6964 .B......sta.ssid
00000110: 0000 0000 0000 0000 2400 ffff 734c d08c ........$...sL..
00000120: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000130: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000140: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000150: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000160: 0248 01ff 0ce6 3d50 7374 612e 7373 6964 .H....=Psta.ssid
00000170: 0000 0000 0000 0000 2400 0000 0100 ffff ........$.......
00000180: 0242 0200 3788 3252 7374 612e 6d61 6300 .B..7.2Rsta.mac.
00000190: 0000 0000 0000 0000 0600 ffff 5cb3 e40f ............\...
000001a0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000001b0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000001c0: 0248 01ff d0eb ce67 7374 612e 6d61 6300 .H.....gsta.mac.
000001d0: 0000 0000 0000 0000 0600 0000 0100 ffff ................
000001e0: 0201 01ff 2e92 65d4 7374 612e 6175 7468 ......e.sta.auth
000001f0: 6d6f 6465 0000 0000 01ff ffff ffff ffff mode............
00000200: 0242 0400 dffa a1fa 7374 612e 7073 7764 .B......sta.pswd
00000210: 0000 0000 0000 0000 4100 ffff 9d33 8936 ........A....3.6
00000220: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000230: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000240: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000250: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000260: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000270: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000280: 0248 01ff 884b 1150 7374 612e 7073 7764 .H...K.Psta.pswd
00000290: 0000 0000 0000 0000 4100 0000 0100 ffff ........A.......
000002a0: 0242 0200 a398 6553 7374 612e 706d 6b00 .B....eSsta.pmk.
000002b0: 0000 0000 0000 0000 2000 ffff 5901 9919 ........ ...Y...
000002c0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000002d0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000002e0: 0248 01ff e293 d8f9 7374 612e 706d 6b00 .H......sta.pmk.
000002f0: 0000 0000 0000 0000 2000 0000 0100 ffff ........ .......
00000300: 0201 01ff 21e5 153b 7374 612e 6368 616e ....!..;sta.chan
00000310: 0000 0000 0000 0000 00ff ffff ffff ffff ................
00000320: 0201 01ff 859b 696a 6175 746f 2e63 6f6e ......ijauto.con
00000330: 6e00 0000 0000 0000 01ff ffff ffff ffff n...............
00000340: 0201 01ff 4ab2 790d 6273 7369 642e 7365 ....J.y.bssid.se
00000350: 7400 0000 0000 0000 00ff ffff ffff ffff t...............
00000360: 0242 0200 268b db98 7374 612e 6273 7369 .B..&...sta.bssi
00000370: 6400 0000 0000 0000 0600 ffff 5cb3 e40f d...........\...
00000380: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000390: ffff ffff ffff ffff ffff ffff ffff ffff ................
000003a0: 0248 01ff c1e8 27ad 7374 612e 6273 7369 .H....'.sta.bssi
000003b0: 6400 0000 0000 0000 0600 0000 0100 ffff d...............
000003c0: 0202 01ff 4747 fae1 7374 612e 6c69 735f ....GG..sta.lis_
000003d0: 696e 7476 616c 0000 0300 ffff ffff ffff intval..........
000003e0: 0201 01ff bdad 9d90 7374 612e 7068 796d ........sta.phym
000003f0: 0000 0000 0000 0000 03ff ffff ffff ffff ................
00000400: 0201 01ff 9ad5 2ab8 7374 612e 7068 7962 ......*.sta.phyb
00000410: 7700 0000 0000 0000 02ff ffff ffff ffff w...............
00000420: 0242 0200 dd79 1eb7 7374 612e 6170 7377 .B...y..sta.apsw
00000430: 0000 0000 0000 0000 0200 ffff 00ed d941 ...............A
00000440: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000450: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000460: 0248 01ff b38d 979e 7374 612e 6170 7377 .H......sta.apsw
00000470: 0000 0000 0000 0000 0200 0000 0100 ffff ................
00000480: 0242 1700 a2e1 fc37 7374 612e 6170 696e .B.....7sta.apin
00000490: 666f 0000 0000 0000 bc02 ffff 5754 b5a4 fo..........WT..
000004a0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000004b0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000004c0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000004d0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000004e0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000004f0: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000500: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000510: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000520: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000530: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000540: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000550: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000560: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000570: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000580: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000590: ffff ffff ffff ffff ffff ffff ffff ffff ................
000005a0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000005b0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000005c0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000005d0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000005e0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000005f0: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000600: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000610: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000620: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000630: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000640: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000650: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000660: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000670: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000680: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000690: ffff ffff ffff ffff ffff ffff ffff ffff ................
000006a0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000006b0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000006c0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000006d0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000006e0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000006f0: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000700: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000710: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000720: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000730: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000740: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000750: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000760: 0248 01ff 25be d3fc 7374 612e 6170 696e .H..%...sta.apin
00000770: 666f 0000 0000 0000 bc02 0000 0100 ffff fo..............
00000780: 0201 01ff cd66 eace 7374 612e 7363 616e .....f..sta.scan
00000790: 5f6d 6574 686f 6400 00ff ffff ffff ffff _method.........
000007a0: 0201 01ff f4b1 7bcf 7374 612e 736f 7274 ......{.sta.sort
000007b0: 5f6d 6574 686f 6400 00ff ffff ffff ffff _method.........
000007c0: 0211 01ff 1c92 d883 7374 612e 6d69 6e72 ........sta.minr
000007d0: 7373 6900 0000 0000 81ff ffff ffff ffff ssi.............
000007e0: 0201 01ff 7cf9 6953 7374 612e 6d69 6e61 ....|.iSsta.mina
000007f0: 7574 6800 0000 0000 00ff ffff ffff ffff uth.............
00000800: 0242 0300 a8ee 9331 6170 2e73 7369 6400 .B.....1ap.ssid.
00000810: 0000 0000 0000 0000 2400 ffff 734c d08c ........$...sL..
00000820: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000830: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000840: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000850: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000860: 0248 01ff 3081 206a 6170 2e73 7369 6400 .H..0. jap.ssid.
00000870: 0000 0000 0000 0000 2400 0000 0100 ffff ........$.......
00000880: 0242 0200 2b40 dac7 6170 2e6d 6163 0000 .B..+#..ap.mac..
00000890: 0000 0000 0000 0000 0600 ffff 5cb3 e40f ............\...
000008a0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000008b0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000008c0: 0248 01ff cc23 26f2 6170 2e6d 6163 0000 .H...#&.ap.mac..
000008d0: 0000 0000 0000 0000 0600 0000 0100 ffff ................
000008e0: 0242 0400 c8c4 0101 6170 2e70 6173 7377 .B......ap.passw
000008f0: 6400 0000 0000 0000 4100 ffff 9d33 8936 d.......A....3.6
00000900: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000910: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000920: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000930: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000940: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000950: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000960: 0248 01ff 9f75 b1ab 6170 2e70 6173 7377 .H...u..ap.passw
00000970: 6400 0000 0000 0000 4100 0000 0100 ffff d.......A.......
00000980: 0242 0200 8dff 205e 6170 2e70 6d6b 0000 .B.... ^ap.pmk..
00000990: 0000 0000 0000 0000 2000 ffff 5901 9919 ........ ...Y...
000009a0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000009b0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000009c0: 0248 01ff ccf4 9df4 6170 2e70 6d6b 0000 .H......ap.pmk..
000009d0: 0000 0000 0000 0000 2000 0000 0100 ffff ........ .......
000009e0: 0201 01ff 6e02 d833 6170 2e63 6861 6e00 ....n..3ap.chan.
000009f0: 0000 0000 0000 0000 01ff ffff ffff ffff ................
00000a00: 0201 01ff 557b 5978 6170 2e61 7574 686d ....U{Yxap.authm
00000a10: 6f64 6500 0000 0000 00ff ffff ffff ffff ode.............
00000a20: 0201 01ff b83a 7e76 6170 2e68 6964 6465 .....:~vap.hidde
00000a30: 6e00 0000 0000 0000 00ff ffff ffff ffff n...............
00000a40: 0201 01ff f15a 1858 6170 2e6d 6178 2e63 .....Z.Xap.max.c
00000a50: 6f6e 6e00 0000 0000 04ff ffff ffff ffff onn.............
00000a60: 0202 01ff 3d27 e857 6263 6e2e 696e 7465 ....='.Wbcn.inte
00000a70: 7276 616c 0000 0000 6400 ffff ffff ffff rval....d.......
00000a80: 0201 01ff f16e 62b1 6170 2e70 6879 6d00 .....nb.ap.phym.
00000a90: 0000 0000 0000 0000 03ff ffff ffff ffff ................
00000aa0: 0201 01ff 3f78 91cf 6170 2e70 6879 6277 ....?x..ap.phybw
00000ab0: 0000 0000 0000 0000 02ff ffff ffff ffff ................
00000ac0: 0201 01ff 1696 af9c 6170 2e73 6e64 6368 ........ap.sndch
00000ad0: 616e 0000 0000 0000 01ff ffff ffff ffff an..............
00000ae0: 0201 01ff fc04 cff4 6c6f 7261 7465 0000 ........lorate..
00000af0: 0000 0000 0000 0000 00ff ffff ffff ffff ................
00000b00: 0242 0280 a5a5 f660 7374 612e 6d61 6300 .B.....`sta.mac.
00000b10: 0000 0000 0000 0000 0600 ffff a681 622b ..............b+
00000b20: 240a c414 b8b4 ffff ffff ffff ffff ffff $...............
00000b30: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000b40: 0248 01ff 50f0 fb86 7374 612e 6d61 6300 .H..P...sta.mac.
00000b50: 0000 0000 0000 0000 0600 0000 0180 ffff ................
00000b60: 0242 0280 0944 7ec8 6170 2e6d 6163 0000 .B...D~.ap.mac..
00000b70: 0000 0000 0000 0000 0600 ffff 30b1 655c ............0.e\
00000b80: 240a c414 b8b5 ffff ffff ffff ffff ffff $...............
00000b90: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000ba0: 0248 01ff 4c38 1313 6170 2e6d 6163 0000 .H..L8..ap.mac..
00000bb0: 0000 0000 0000 0000 0600 0000 0180 ffff ................
00000bc0: 0001 01ff 477b 1363 7068 7900 0000 0000 ....G{.cphy.....
00000bd0: 0000 0000 0000 0000 03ff ffff ffff ffff ................
00000be0: 0342 2100 0ec0 4c91 6361 6c5f 6461 7461 .B!...L.cal_data
00000bf0: 0000 0000 0000 0000 0004 ffff 18cf 6acc ..............j.
00000c00: 0610 0000 240a c414 b8b4 0000 6488 0000 ....$.......d...
00000c10: 0000 3000 494b 0000 6488 0000 8808 3000 ..0.IK..d.....0.
00000c20: 494b 0000 6488 0000 1111 3000 494b 0000 IK..d.....0.IK..
00000c30: 6488 0000 9919 3000 494b 0000 6488 0000 d.....0.IK..d...
00000c40: 2222 3000 494b 0000 6488 0000 ab2a 3000 ""0.IK..d....*0.
00000c50: 494b 0000 6488 0000 3333 3000 494b 0000 IK..d...330.IK..
00000c60: 6388 0000 bb3b 3000 484b 0000 6388 0000 c....;0.HK..c...
00000c70: 4444 3000 484b 0000 6388 0000 cd4c 3000 DD0.HK..c....L0.
00000c80: 484b 0000 6288 0000 5555 3000 484b 0000 HK..b...UU0.HK..
00000c90: 6288 0000 de5d 3000 484b 0000 6288 0000 b....]0.HK..b...
00000ca0: 6666 3000 484b 0000 6288 0000 ef6e 3000 ff0.HK..b....n0.
00000cb0: 484b 0000 6288 0000 7777 3000 484b 0000 HK..b...ww0.HK..
00000cc0: 6188 0000 0080 3000 484a 0000 6188 0000 a.....0.HJ..a...
00000cd0: 8888 3000 484a 0000 6188 0000 1191 3000 ..0.HJ..a.....0.
00000ce0: 484a 0000 6188 0000 9999 3000 484a 0000 HJ..a.....0.HJ..
00000cf0: 5f88 0000 22a2 3000 484a 0000 5f88 0000 _...".0.HJ.._...
00000d00: abaa 3000 484a 0000 5f88 0000 33b3 3000 ..0.HJ.._...3.0.
00000d10: 484a 0000 5f88 0000 bbbb 3000 484a 0000 HJ.._.....0.HJ..
00000d20: 5f88 0000 44c4 3000 484a 0000 5f88 0000 _...D.0.HJ.._...
00000d30: cdcc 3000 484a 0000 5e88 0000 55d5 3000 ..0.HJ..^...U.0.
00000d40: 484a 0000 5e88 0000 dedd 3000 484a 0000 HJ..^.....0.HJ..
00000d50: 5e88 0000 66e6 3000 484a 0000 5e88 0000 ^...f.0.HJ..^...
00000d60: efee 3000 484a 0000 5e88 0000 77f7 3000 ..0.HJ..^...w.0.
00000d70: 484a 0000 5d88 0000 0000 3100 484a 0000 HJ..].....1.HJ..
00000d80: 5d88 0000 8808 3100 484a 0000 5d88 0000 ].....1.HJ..]...
00000d90: 1111 3100 484a 0000 5c88 0000 9919 3100 ..1.HJ..\.....1.
00000da0: 484a 0000 5c88 0000 2222 3100 484a 0000 HJ..\...""1.HJ..
00000db0: 5c88 0000 ab2a 3100 484a 0000 5c88 0000 \....*1.HJ..\...
00000dc0: 3333 3100 484a 0000 5c88 0000 bb3b 3100 331.HJ..\....;1.
00000dd0: 484a 0000 5b88 0000 4444 3100 484a 0000 HJ..[...DD1.HJ..
00000de0: 5b88 0000 cd4c 3100 484a 0000 5b88 0000 [....L1.HJ..[...
00000df0: 5555 3100 484a 0000 5b88 0000 de5d 3100 UU1.HJ..[....]1.
00000e00: 484a 0000 5a88 0000 6666 3100 484a 0000 HJ..Z...ff1.HJ..
00000e10: 5a88 0000 ef6e 3100 484a 0000 5a88 0000 Z....n1.HJ..Z...
00000e20: 7777 3100 484a 0000 5a88 0000 0080 3100 ww1.HJ..Z.....1.
00000e30: 484a 0000 5a88 0000 8888 3100 484a 0000 HJ..Z.....1.HJ..
00000e40: 5988 0000 1191 3100 474a 0000 5988 0000 Y.....1.GJ..Y...
00000e50: 9999 3100 474a 0000 5988 0000 22a2 3100 ..1.GJ..Y...".1.
00000e60: 474a 0000 5988 0000 abaa 3100 474a 0000 GJ..Y.....1.GJ..
00000e70: 5788 0000 33b3 3100 4749 0000 5788 0000 W...3.1.GI..W...
00000e80: bbbb 3100 4749 0000 5788 0000 44c4 3100 ..1.GI..W...D.1.
00000e90: 4749 0000 5788 0000 cdcc 3100 4749 0000 GI..W.....1.GI..
00000ea0: 5688 0000 55d5 3100 4749 0000 5688 0000 V...U.1.GI..V...
00000eb0: dedd 3100 4749 0000 5688 0000 66e6 3100 ..1.GI..V...f.1.
00000ec0: 4749 0000 5688 0000 efee 3100 4749 0000 GI..V.....1.GI..
00000ed0: 5688 0000 77f7 3100 4749 0000 5588 0000 V...w.1.GI..U...
00000ee0: 0000 3200 4749 0000 5588 0000 8808 3200 ..2.GI..U.....2.
00000ef0: 4749 0000 5588 0000 1111 3200 4749 0000 GI..U.....2.GI..
00000f00: 5588 0000 9919 3200 4749 0000 5388 0000 U.....2.GI..S...
00000f10: 2222 3200 4749 0000 5388 0000 ab2a 3200 ""2.GI..S....*2.
00000f20: 4749 0000 5388 0000 3333 3200 4749 0000 GI..S...332.GI..
00000f30: 5388 0000 bb3b 3200 4749 0000 5388 0000 S....;2.GI..S...
00000f40: 4444 3200 4749 0000 5388 0000 cd4c 3200 DD2.GI..S....L2.
00000f50: 4749 0000 5388 0000 5555 3200 4749 0000 GI..S...UU2.GI..
00000f60: 5388 0000 de5d 3200 4749 0000 5288 0000 S....]2.GI..R...
00000f70: 6666 3200 4749 0000 5288 0000 ef6e 3200 ff2.GI..R....n2.
00000f80: 4749 0000 5288 0000 7777 3200 4749 0000 GI..R...ww2.GI..
00000f90: 5288 0000 0080 3200 4749 0000 5288 0000 R.....2.GI..R...
00000fa0: 8888 3200 4749 0000 5188 0000 1191 3200 ..2.GI..Q.....2.
00000fb0: 4749 0000 5188 0000 9999 3200 4749 0000 GI..Q.....2.GI..
00000fc0: 5188 0000 22a2 3200 4749 0000 5188 0000 Q...".2.GI..Q...
00000fd0: abaa 3200 4749 0000 4f88 0000 33b3 3200 ..2.GI..O...3.2.
00000fe0: 4648 0000 4f88 0000 bbbb 3200 4648 0000 FH..O.....2.FH..
00000ff0: 4f88 0000 44c4 3200 4648 0000 4f88 0000 O...D.2.FH..O...
00001000: feff ffff 0100 0000 feff ffff ffff ffff ................
00001010: ffff ffff ffff ffff ffff ffff a348 9f38 .............H.8
00001020: aaaa aaaa aaaa aaaa faff ffff ffff ffff ................
00001030: ffff ffff ffff ffff ffff ffff ffff ffff ................
00001040: 0342 1d01 23fd a9bb 6361 6c5f 6461 7461 .B..#...cal_data
00001050: 0000 0000 0000 0000 7003 ffff 3650 2b44 ........p...6P+D
00001060: cdcc 3200 4648 0000 0000 0000 f8ff ff00 ..2.FH..........
00001070: 0000 0000 0000 0000 0901 0001 0001 0101 ................
00001080: 0801 0201 0101 ff00 0501 0101 0001 ff00 ................
00001090: 0301 0001 0301 0001 0301 0001 fe00 ff00 ................
000010a0: 3900 f907 0300 c507 c507 4607 0f07 030f 9.........F.....
000010b0: 0703 0f07 030f 0703 b707 94fe 250b 0000 ............%...
000010c0: 4343 1717 5757 4e48 423c 3834 f5fe 040a CC..WWNHB<84....
000010d0: 0e11 f6ff 050b 0f13 f7fe 040b 0f13 f7fe ................
000010e0: 040b 0f13 7070 7172 7379 777b 001a 0e18 ....ppqrsyw{....
000010f0: 1814 1a14 1600 2c00 ff00 0101 0000 f907 ......,.........
00001100: b907 b907 1001 ff00 ff00 fe00 0701 fd00 ................
00001110: fe00 ff00 0201 fc00 ff00 fe00 513e 94fe ............Q>..
00001120: 0000 0000 0000 0000 7f00 2001 7b00 100d .......... .{...
00001130: 0000 0100 0200 0300 0400 0004 0104 0204 ................
00001140: 0304 0404 0504 0804 0904 0a04 0030 0130 .............0.0
00001150: 0230 0330 0430 0530 0034 0134 0234 0334 .0.0.0.0.4.4.4.4
00001160: 0434 0038 0138 0238 0040 0140 0240 0340 .4.8.8.8.#.#.#.#
00001170: 0440 0540 0044 0144 0244 0344 0444 0048 .#.#.D.D.D.D.D.H
00001180: 0148 0248 0348 0448 0548 0848 0948 0a48 .H.H.H.H.H.H.H.H
00001190: 0b48 0c48 0d48 1848 1948 1a48 1b48 1c48 .H.H.H.H.H.H.H.H
000011a0: 1d48 3848 3948 3a48 3b48 3c48 3d48 0000 .H8H9H:H;H<H=H..
000011b0: 0000 0000 0000 0000 0000 0000 0000 0100 ................
000011c0: 0200 0300 0400 0004 0104 0204 0304 0404 ................
000011d0: 0504 0804 0904 0a04 0030 0130 0230 0330 .........0.0.0.0
000011e0: 0430 0530 0034 0134 0234 0334 0434 0038 .0.0.4.4.4.4.4.8
000011f0: 0138 0238 0040 0140 0240 0340 0440 0540 .8.8.#.#.#.#.#.#
00001200: 0044 0144 0244 0344 0444 0048 0148 0248 .D.D.D.D.D.H.H.H
00001210: 0348 0050 0150 0250 0350 0450 0550 0054 .H.P.P.P.P.P.P.T
00001220: 0154 0254 0354 0058 0158 0258 0358 0458 .T.T.T.X.X.X.X.X
00001230: 005c 015c 025c 035c 045c 055c 085c 095c .\.\.\.\.\.\.\.\
00001240: 0a5c 0b5c 0c5c 0d5c 185c 195c 1a5c 1b5c .\.\.\.\.\.\.\.\
00001250: 1c5c 1d5c 385c 395c 3a5c 3b5c 3c5c 3d5c .\.\8\9\:\;\<\=\
00001260: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001270: d800 eb00 d000 e200 d200 e600 d100 e300 ................
00001280: d100 df00 d400 e600 d200 e500 d200 dd00 ................
00001290: f300 fa00 f300 fa00 f300 fa00 f300 fa00 ................
000012a0: f300 f700 f300 f700 f300 f700 f300 f700 ................
000012b0: f300 fa00 f300 fa00 f300 fa00 f300 f500 ................
000012c0: f300 f500 f300 f500 f300 f500 f700 f300 ................
000012d0: f700 f300 f400 f300 f400 f300 f400 f300 ................
000012e0: f400 f300 f400 f300 f400 f300 f400 f300 ................
000012f0: ec00 f300 e700 0001 e700 0001 e700 0001 ................
00001300: e500 0001 e500 0001 e500 0001 7158 2abd ............qX*.
00001310: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001320: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001330: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001340: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001350: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001360: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001370: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001380: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00001390: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000013a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000013b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000013c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000013d0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000013e0: 0348 01ff d2a2 cfb8 6361 6c5f 6461 7461 .H......cal_data
000013f0: 0000 0000 0000 0000 7007 0000 0200 ffff ........p.......
00001400: 0342 0200 a6f3 826c 6361 6c5f 6d61 6300 .B.....lcal_mac.
00001410: 0000 0000 0000 0000 0600 ffff a681 622b ..............b+
00001420: 240a c414 b8b4 ffff ffff ffff ffff ffff $...............
00001430: ffff ffff ffff ffff ffff ffff ffff ffff ................
00001440: 0348 01ff 608c 90c6 6361 6c5f 6d61 6300 .H..`...cal_mac.
00001450: 0000 0000 0000 0000 0600 0000 0100 ffff ................
00001460: 0304 01ff 32ce c600 6361 6c5f 7665 7273 ....2...cal_vers
00001470: 696f 6e00 0000 0000 0610 0000 ffff ffff ion.............
00001480: ffff ffff ffff ffff ffff ffff ffff ffff ................
00001490: ffff ffff ffff ffff ffff ffff ffff ffff ................
000014a0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000014b0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000014c0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000014d0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000014e0: ffff ffff ffff ffff ffff ffff ffff ffff ................
000014f0: ffff ffff ffff ffff ffff ffff ffff ffff ................
<snip>
00003ff0: ffff ffff ffff ffff ffff ffff ffff ffff ................

01 1011 - 11 1101 = ? use 2's complement

I'm trying to figure out this doozie: 01 1011 - 11 1101
use 2's complement to solve, 6bits signed.
This is what I tried:
range of 6bits: -32 to 31
01 1011 = 27
11 1101 = -29
27 -(-29) = 56 (overflow)
11 1101 -- 2s complement --> 10 0011
so
01 1011 + 10 0011 = (missing bit)11 1110 = -2!
Any luck?
Ok so I think I figured it out:
my first mistake was that 11 1101 is not -29 but -3.
SO:
01 1011 = 27
11 1101 = -3
27 -(-3) = 30
I can do a reverse 2's complement of -3 which is:
11 1101 - 1 = 11 1100
then I flip 11 1100 which gives me 00 0011.
so
01 1011 + 00 0011 = 01 1110 = 30
:)

MIPS: Calculating BEQ into Hexadecimal Machine Code

I have an assignment where I have to convert MIPS instructions into its hexadecimal machine code. I know how to convert the add, addi, lw, etc. instructions just fine, but when it gets to instructions like beq, I get confused. How would I convert this beq to hex?
0x00400108 beq $t3, $t5, NEXT
0x0040010C j END
where the address of NEXT is
0x0040011C
?
What I've tried:
beq opcode = 4
$t3 = register 11
$t5 = register 13
NEXT = 0x0040011C - 0x0040010C = 10 (hex) = 16 (decimal)
4 11 13 16 (decimal)
000100 01011 01101 0000 0000 0000 1000 (convert to binary)
0001 0001 0110 1101 0000 0000 0000 1000 (group into fours)
1 1 6 D 0 0 0 8 (hexadecimal)
but it's wrong...
After spending a long time being dumb, I've found the correct answer.
The summarized code:
beq $t3, $t5, NEXT
[instruction 1]
[instruction 2]
[instruction 3]
[instruction 4]
NEXT: [instruction 5]
As Michael said, the offset is the number of words from the instruction following the branch instruction. Instruction 1 is the following instruction after beq, so start counting from there till NEXT. There are 4 instructions from instruction 1 and NEXT, so the format for beq is now:
op | rs | rd | 16-bit constant or address
000100 | 01011 | 01101 | 0000 0000 0001 0000
Where rs is $t3 and rd is $t5.
Regrouped and converted into hex:
0001 | 0001 | 0110 | 1101 | 0000 0000 0001 0000
1 | 1 | 6 | D | 0 0 1 0
So the hexadecimal representation is 116D0010. Cheers.
Edit:Instructions are Words, 4 Instructions * 4 Bytes = 16 bytes
Since the instructions have a offset of 3 commands from where the pc put in 3 and not 4 into the offset. Thus the binary rep is 0001 | 0001 | 0110 | 1101 | 0000 0000 0000 0011 and not what the edited answer says about multiplying by 4.
Check out the example in this pdf: https://ai.berkeley.edu/~cs61c/sp17/lec/11/lec11.pdf