diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
index cfe98b5e94be..55a5873edc18 100644
--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -47,7 +47,7 @@ static unsigned int current_flags = S390_INSTR_FLAG_FACILITY_MASK;
 static unsigned int current_mode_mask = 0;
 
 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
-   for the output file.  */
+   for the output file. The default is picked in init_default_arch().  */
 static bool set_highgprs_p = false;
 
 /* Whether to use user friendly register names. Default is TRUE.  */
@@ -221,6 +221,7 @@ size_t md_longopts_size = sizeof (md_longopts);
 static void
 init_default_arch (void)
 {
+  /* Default architecture size.  */
   if (strcmp (default_arch, "s390") == 0)
     {
       if (s390_arch_size == 0)
@@ -234,6 +235,7 @@ init_default_arch (void)
   else
     as_fatal (_("Invalid default architecture, broken assembler."));
 
+  /* Default current architecture mode.  */
   if (current_mode_mask == 0)
     {
       /* Default to z/Architecture mode if the CPU supports it.  */
@@ -242,6 +244,10 @@ init_default_arch (void)
       else
 	current_mode_mask = 1 << S390_OPCODE_ZARCH;
     }
+
+  /* Determine whether the highgprs flag in the ELF header needs to be set.  */
+  if ((s390_arch_size == 32) && (current_mode_mask & (1 << S390_OPCODE_ZARCH)))
+    set_highgprs_p = true;
 }
 
 /* Called by TARGET_FORMAT.  */
@@ -419,11 +425,7 @@ md_parse_option (int c, const char *arg)
 	current_mode_mask = 1 << S390_OPCODE_ESA;
 
       else if (arg != NULL && strcmp (arg, "zarch") == 0)
-	{
-	  if (s390_arch_size == 32)
-	    set_highgprs_p = true;
-	  current_mode_mask = 1 << S390_OPCODE_ZARCH;
-	}
+	current_mode_mask = 1 << S390_OPCODE_ZARCH;
 
       else if (arg != NULL && startswith (arg, "arch="))
 	{
diff --git a/gas/testsuite/gas/s390/blank.s b/gas/testsuite/gas/s390/blank.s
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/gas/testsuite/gas/s390/esa-highgprs-0.d b/gas/testsuite/gas/s390/esa-highgprs-0.d
new file mode 100644
index 000000000000..aa9eff70cfeb
--- /dev/null
+++ b/gas/testsuite/gas/s390/esa-highgprs-0.d
@@ -0,0 +1,24 @@
+#name: s390 highgprs 0
+#source: blank.s
+#readelf: -h
+
+ELF Header:
+  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 
+  Class:                             ELF32
+  Data:                              2's complement, big endian
+  Version:                           1 \(current\)
+  OS/ABI:                            UNIX - System V
+  ABI Version:                       0
+  Type:                              REL \(Relocatable file\)
+  Machine:                           IBM S/390
+  Version:                           0x1
+  Entry point address:               0x0
+  Start of program headers:          0 \(bytes into file\)
+  Start of section headers:          164 \(bytes into file\)
+  Flags:                             0x0
+  Size of this header:               52 \(bytes\)
+  Size of program headers:           0 \(bytes\)
+  Number of program headers:         0
+  Size of section headers:           40 \(bytes\)
+  Number of section headers:         7
+  Section header string table index: 6
diff --git a/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.d b/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.d
new file mode 100644
index 000000000000..483342f3f8bd
--- /dev/null
+++ b/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.d
@@ -0,0 +1,23 @@
+#name: s390 highgprs machinemode 0
+#readelf: -h
+
+ELF Header:
+  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 
+  Class:                             ELF32
+  Data:                              2's complement, big endian
+  Version:                           1 \(current\)
+  OS/ABI:                            UNIX - System V
+  ABI Version:                       0
+  Type:                              REL \(Relocatable file\)
+  Machine:                           IBM S/390
+  Version:                           0x1
+  Entry point address:               0x0
+  Start of program headers:          0 \(bytes into file\)
+  Start of section headers:          164 \(bytes into file\)
+  Flags:                             0x0
+  Size of this header:               52 \(bytes\)
+  Size of program headers:           0 \(bytes\)
+  Number of program headers:         0
+  Size of section headers:           40 \(bytes\)
+  Number of section headers:         7
+  Section header string table index: 6
diff --git a/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.s b/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.s
new file mode 100644
index 000000000000..60d9e3f56781
--- /dev/null
+++ b/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.s
@@ -0,0 +1,2 @@
+.text
+	.machinemode zarch_nohighgprs
diff --git a/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.d b/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.d
new file mode 100644
index 000000000000..c1adc1603b23
--- /dev/null
+++ b/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.d
@@ -0,0 +1,23 @@
+#name: s390 highgprs machinemode 1
+#readelf: -h
+
+ELF Header:
+  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 
+  Class:                             ELF32
+  Data:                              2's complement, big endian
+  Version:                           1 \(current\)
+  OS/ABI:                            UNIX - System V
+  ABI Version:                       0
+  Type:                              REL \(Relocatable file\)
+  Machine:                           IBM S/390
+  Version:                           0x1
+  Entry point address:               0x0
+  Start of program headers:          0 \(bytes into file\)
+  Start of section headers:          164 \(bytes into file\)
+  Flags:                             0x1, highgprs
+  Size of this header:               52 \(bytes\)
+  Size of program headers:           0 \(bytes\)
+  Number of program headers:         0
+  Size of section headers:           40 \(bytes\)
+  Number of section headers:         7
+  Section header string table index: 6
diff --git a/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.s b/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.s
new file mode 100644
index 000000000000..c46b95b7e95d
--- /dev/null
+++ b/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.s
@@ -0,0 +1,3 @@
+.text
+	.machinemode zarch
+	.machinemode esa
diff --git a/gas/testsuite/gas/s390/s390.exp b/gas/testsuite/gas/s390/s390.exp
index 7fbc7f8a7515..b63c09e40324 100644
--- a/gas/testsuite/gas/s390/s390.exp
+++ b/gas/testsuite/gas/s390/s390.exp
@@ -12,6 +12,16 @@ if [expr [istarget "s390-*-*"] ||  [istarget "s390x-*-*"]]  then {
       run_dump_test "esa-z9-109" "{as -m31} {as -march=z9-109}"
       run_dump_test "esa-reloc" "{as -m31}"
       run_dump_test "esa-operands" "{as -m31}"
+      run_dump_test "esa-highgprs-0" "{as -m31} {as -mesa}"
+      run_dump_test "esa-highgprs-0" "{as -mesa} {as -m31}"
+      run_dump_test "esa-highgprs-0" "{as -m31} {as -march=g5}"
+      run_dump_test "zarch-highgprs-1" "{as -m31} {as -mzarch}"
+      run_dump_test "zarch-highgprs-1" "{as -mzarch} {as -m31}"
+      run_dump_test "zarch-highgprs-1" "{as -m31} {as -march=z900}"
+      run_dump_test "esa-highgprs-machinemode-0" "{as -m31} {as -mesa}"
+      run_dump_test "esa-highgprs-machinemode-0" "{as -mesa} {as -m31}"
+      run_dump_test "esa-highgprs-machinemode-1" "{as -m31} {as -mesa}"
+      run_dump_test "esa-highgprs-machinemode-1" "{as -mesa} {as -m31}"
     }
 
 #    # PIC is only supported on ELF targets.
@@ -44,6 +54,8 @@ if [expr [istarget "s390-*-*"] ||  [istarget "s390x-*-*"]]  then {
     run_list_test "machine-parsing-4" ""
     run_list_test "machine-parsing-5" ""
     run_list_test "machine-parsing-6" ""
+    run_dump_test "zarch-highgprs-0" "{as -m64} {as -mzarch}"
+    run_dump_test "zarch-highgprs-0" "{as -mzarch} {as -m64}"
     run_dump_test "zarch-omitted-base-index" "{as -m64}"
     run_list_test "zarch-omitted-base-index-err" ""
 }
diff --git a/gas/testsuite/gas/s390/zarch-highgprs-0.d b/gas/testsuite/gas/s390/zarch-highgprs-0.d
new file mode 100644
index 000000000000..53cc3e057652
--- /dev/null
+++ b/gas/testsuite/gas/s390/zarch-highgprs-0.d
@@ -0,0 +1,24 @@
+#name: s390x highgprs 0
+#source: blank.s
+#readelf: -h
+
+ELF Header:
+  Magic:   7f 45 4c 46 02 02 01 00 00 00 00 00 00 00 00 00 
+  Class:                             ELF64
+  Data:                              2's complement, big endian
+  Version:                           1 \(current\)
+  OS/ABI:                            UNIX - System V
+  ABI Version:                       0
+  Type:                              REL \(Relocatable file\)
+  Machine:                           IBM S/390
+  Version:                           0x1
+  Entry point address:               0x0
+  Start of program headers:          0 \(bytes into file\)
+  Start of section headers:          208 \(bytes into file\)
+  Flags:                             0x0
+  Size of this header:               64 \(bytes\)
+  Size of program headers:           0 \(bytes\)
+  Number of program headers:         0
+  Size of section headers:           64 \(bytes\)
+  Number of section headers:         7
+  Section header string table index: 6
diff --git a/gas/testsuite/gas/s390/zarch-highgprs-1.d b/gas/testsuite/gas/s390/zarch-highgprs-1.d
new file mode 100644
index 000000000000..d351032fbc47
--- /dev/null
+++ b/gas/testsuite/gas/s390/zarch-highgprs-1.d
@@ -0,0 +1,24 @@
+#name: s390x highgprs 0
+#source: blank.s
+#readelf: -h
+
+ELF Header:
+  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 
+  Class:                             ELF32
+  Data:                              2's complement, big endian
+  Version:                           1 \(current\)
+  OS/ABI:                            UNIX - System V
+  ABI Version:                       0
+  Type:                              REL \(Relocatable file\)
+  Machine:                           IBM S/390
+  Version:                           0x1
+  Entry point address:               0x0
+  Start of program headers:          0 \(bytes into file\)
+  Start of section headers:          164 \(bytes into file\)
+  Flags:                             0x1, highgprs
+  Size of this header:               52 \(bytes\)
+  Size of program headers:           0 \(bytes\)
+  Number of program headers:         0
+  Size of section headers:           40 \(bytes\)
+  Number of section headers:         7
+  Section header string table index: 6
