diff --git a/py/gc.c b/py/gc.c
index 86db78f84e3756354c1e354f127be4bda9c37d47..7e9b2c53c0daed7215afa2cc5c850ea76b3b35dd 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -680,10 +680,11 @@ void gc_dump_alloc_table(void) {
                 }
             }
             // print header for new line of blocks
+            // (the cast to uint32_t is for 16-bit ports)
             #if EXTENSIVE_HEAP_PROFILING
-            printf("\n%05x: ", (uint)(bl * BYTES_PER_BLOCK) & 0xfffff);
+            printf("\n%05x: ", (uint)((bl * BYTES_PER_BLOCK) & (uint32_t)0xfffff));
             #else
-            printf("\n%05x: ", (uint)PTR_FROM_BLOCK(bl) & 0xfffff);
+            printf("\n%05x: ", (uint)(PTR_FROM_BLOCK(bl) & (uint32_t)0xfffff));
             #endif
         }
         int c = ' ';